473,412 Members | 3,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Update records

bhcob1
19
Hey Guys,

I have a db, with a table tblCSOC, there are 4 fields that are releveatn to my question:
tblCSOC
[CSOC Number] - primary key
[Issue] - primary key
[Latest Issue] - checkbox
[ID] - autonumber
The autonumber key was created so i could uniuqly identify each record.

I want a button which i click that will go thru the table, and for each record, find out if that is the latest issue for that CSOC number, and if so set [Latest Issue] to true.

I have been messing around with the Max function in a query, and also using record sets.

I am using Access 2000. Here is my code, any suggestions or ideas on how i could go about this...super.

Go easy on me, my debut to the post world

Sub Command118_Click()

'Use a nonreadonly lock type to be able to delete records.
Set rsMyTable1 = New ADODB.Recordset
rsMyTable1.ActiveConnection = CurrentProject.Connection
rsMyTable1.Open "qryCSOCIssueUpdate", , adOpenKeyset, adLockOptimistic, _
adCmdTable

Set rsMyTable2 = New ADODB.Recordset
rsMyTable2.ActiveConnection = CurrentProject.Connection
rsMyTable2.Open "tblCSOC", , adOpenKeyset, adLockOptimistic, _
adCmdTable

'Loop through recordset.
Do Until rsMyTable1.EOF
rsMyTable2.MoveFirst
Do Until rsMyTable2.EOF
If (rsMyTable1.Fields("FirstOfID") = rsMyTable2.Fields("ID")) Then
rsMyTable2.Fields("Latest Issue") = True
Else: rsMyTable2.Fields("Latest Issue") = False
End If
rsMyTable2.MoveNext
Loop

rsMyTable1.MoveNext
Loop

End Sub
Feb 2 '07 #1
5 2181
nico5038
3,080 Expert 2GB
Normally we don't record a latest issue this way.
It would imply that after every change the procedure would need to run to make sure that the data is consistent.
When you have the [Issue] as a sequence number, the highest [Issue] will determine the latest issue and can be found like:

select a.[CSOC Number], a.[Issue] from tblCSOC a where [Issue]=(select MAX(b.[Issue]) from tblCSOC b where a.[CSOC Number]=b.[CSOC Number]);

Getting the idea ?

Nic;o)
Feb 2 '07 #2
Rabbit
12,516 Expert Mod 8TB
Nico is right. This would require the code to run everytime a new record is added.

It'd be better to just have code run whenever you need the lastest Issue.

Expand|Select|Wrap|Line Numbers
  1. DMax("Issue", "tblCSOC", "CSOC = '" & CSOC & "'")
  2.  
This will give you the latest Issue for a chosen CSOC Number, assuming that Issue increments. Use a query if you need it for each CSOC Number.

On a different note. It seems as if you can have multiple records with the same CSOC Number in which case it can't be a primary key. And the same may be true for the Issue.
Feb 2 '07 #3
NeoPa
32,556 Expert Mod 16PB
They are both workable ways of determining the value required.
FYI Rabbit. Nico's way is the more efficient as this form can be optimised by the SQL engine and doesn't have the overhead of a function call from within the SQL. If it is required from within ordinary VBA code then the DMax() function is fine.
Feb 4 '07 #4
bhcob1
19
Thanks for that Nico, your code will do me just fine and save me pulling my hair out.

Cheers
Feb 4 '07 #5
nico5038
3,080 Expert 2GB
Glad I could help and success with your application !

Nic;o)
Feb 4 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Reply via newsgroup | last post by:
Folks, When performing an update in mysql (using PHP), can I find out how many records were matched? mysql_affected_rows() won't work... and I have the following problem that I thought I...
1
by: Google Mike | last post by:
I have one table of new records (tableA) that may already exist in tableB. I want to insert these records into tableB with insert if they don't already exist, or update any existing ones with new...
2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
1
by: Michelle | last post by:
Hi all I am having problems creating an update query. I have 2 tables, tblPublishRoster and tblCCAgents_Changed_Shifts. I want to select all records from tblCCAgents_ChangedShifts where...
1
by: Earl Anderson | last post by:
Using WinXP & AccessXP, I'd like to automatically have the records that I've just printed in a report automatically updated to have the 'print date & time' immediately inserted into a 'Date/Time'...
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
3
by: Roy | last post by:
Hi Access gurus, I have a A2K application.The data in the database is updated daily by a excel download.I have a master n related tables keyed in by a OrderID.I have a problem in updating data.If...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.