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
5 2181
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)
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. -
DMax("Issue", "tblCSOC", "CSOC = '" & CSOC & "'")
-
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.
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.
Thanks for that Nico, your code will do me just fine and save me pulling my hair out.
Cheers
Glad I could help and success with your application !
Nic;o)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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'...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |