Hi,
My question retains to a function I made that grabs a lot of data and compares and makes updates to that same record IF it is in both databases. If it is not in both databases, then it keeps going in a loop and never stops running. I need some help, I don't even know if it's possible to tell if you have been through a recordset more than once. How do you just skip a record once it scans through the other database and can't find it?
Here is what I have FYI, don't know if this helps. - 'Update Routine Feeders
-
strSQL = "SELECT tblFeeder.FeederNumber, tblFeeder.MilesBilled FROM (tblCrews INNER JOIN tblContractors ON tblCrews.Contractor = tblContractors.ContractorID) INNER JOIN ((tblDivisions INNER JOIN (tblSubs INNER JOIN tblFeeder ON tblSubs.SubID = tblFeeder.Sub) ON tblDivisions.Division = tblFeeder.Division) INNER JOIN tblPlanSplitYearFeeders ON tblFeeder.FdrID = tblPlanSplitYearFeeders.FdrID) ON tblCrews.CrewID = tblPlanSplitYearFeeders.Crew WHERE (((tblFeeder.NegotiatedFinishDate) Is Not Null) AND ((tblFeeder.Active)=True)) ORDER BY tblFeeder.FeederNumber;"
-
-
Set HATTrecords = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges, dbOptimistic)
-
-
HATTrecords.MoveFirst
-
CAMPrecords.MoveFirst
-
-
'Update the records in HATT with CAMP records
-
While Not HATTrecords.EOF
-
If Not CAMPrecords.EOF Then
-
If CAMPrecords("LOCATION_CODE") = HATTrecords("FeederNumber") Then
-
HATTrecords.Edit
-
HATTrecords("MilesBilled") = CAMPrecords("MilesBilled")
-
HATTrecords.Update
-
HATTrecords.MoveNext
-
End If
-
CAMPrecords.MoveNext
-
Else
-
CAMPrecords.MoveFirst
-
End If
-
Wend
-
-
'Close the recordsets
-
HATTrecords.Close
-
CAMPrecords.Close
-
-
DoCmd.Close acForm, "frmRunningQuery"
-
MsgBox "Done"
-
6 1753 NeoPa 32,556
Expert Mod 16PB
It seems like you're dealing with separate tables rather than databases, but your question leaves much of your requirement to guesswork. Are you simply updating HATTrecords.MilesBilled to CAMPrecords.MilesBilled for all records where CAMPrecords.LOCATION_CODE = HATTrecords.FeederNumber? If so, then you should really be looking to do that in a simple UPDATE query.
Sorry I left out a piece of code. Yes 2 databases (HATTRecords & CAMPRecords). The CAMPRecords has the most recent data, I need it copied to HATTRecords. Did't think of an update query. Wow, seems a lot easier.
NeoPa 32,556
Expert Mod 16PB ANoble1:
Yes 2 databases (HATTRecords & CAMPRecords).
You appear to be trying to agree with me yet contradict me at the same time. I assume you mean "Yes. Two tables." If not, you'll have to make your meaning clearer (or not).
I assume that you're now happy with the idea of an UPDATE query and we can leave this where it is?
I meant Yes 2 Different Databases. Not the same database. But I will give the update query a try if possible.
Yes, thanks for the help.
NeoPa 32,556
Expert Mod 16PB
Go for the update query. I was saying it wasn't separate databases, but just separate tables. Whichever the real situation an UPDATE can be made to work, but it will be harder if the data is referenced via different databases. If it really is so, then it would make sense to link the remote data into the one you're working within and then do it within that one database (Still separate tables of course).
Assuming that the rest of your code is Ok this should do the job. - 'Update the records in HATT with CAMP records
-
HATTrecords.MoveFirst
-
Do While Not HATTrecords.EOF
-
CAMPrecords.MoveFirst
-
Do While Not CAMPrecords.EOF
-
If CAMPrecords("LOCATION_CODE") = HATTrecords("FeederNumber") Then
-
'Update HATT
-
HATTrecords.Edit
-
HATTrecords("MilesBilled") = CAMPrecords("MilesBilled")
-
HATTrecords.Update
-
Exit Do 'The match is find and can't be others
-
End If
-
CAMPrecords.MoveNext
-
Loop
-
HATTrecords.MoveNext
-
Loop
-
-
'Close the recordsets
-
HATTrecords.Close
-
CAMPrecords.Close
-
-
DoCmd.Close acForm, "frmRunningQuery"
-
MsgBox "Done"
I update your code in order to show you how can be done but using an update query is much much faster.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kingdom |
last post by:
I Need some serious help here. strugling novis with ASP and javascript
any help would be greatly appreciated
The script below does exactly what I want it to do for each product on
the two passes...
|
by: Jeff |
last post by:
I have to insert all Items of a listbox to a table ? How can I do that ? The code bellow always add the same first item to the table. must be another way to do this. Thank'
Dim Conn As String =...
|
by: sicapitan |
last post by:
Hi There, not sure if this can be done with SQL or if there is an SQL
crossover
I have two tables:
Table "record":
id, record_id, data1, data2
Table "subrecord":
id, record_id, name, value
|
by: Eric |
last post by:
If i run a query and the process stuck how to i get out from that
query. I can use Ctrl+Alt+Del but it terminate all of the program. I
wrote multiple queries one by one in my program. Is it...
|
by: Genalube |
last post by:
I have an application that will produce a Word document based on five separate queries this has required that I create a ADODB connection:
'Create connection to current database
Dim Conn As...
|
by: starke1120 |
last post by:
I need to write a query that has a criteria of two separate fields (one
compared to another, then a seperate one) but I can't figure out how
to do it. Let me first explain the table
id...
|
by: abouddan |
last post by:
Hi all
I am working on an accounting project using MS Access 2000, that demands to calculate many fields in a spesific record.
The problem:
The query I am using returns many records and for each...
|
by: sonal0228 |
last post by:
how to retrive and display attendance of all students of a class subject wise using servlet
|
by: javediq143 |
last post by:
Hi All,
This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in...
|
by: Katie Howard |
last post by:
Hi,
I’m just starting a database that will contain historical data of all the conferences that our employees have attended over the years. I have 3 tables (Employees, Conferences, and the 3rd is...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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,...
| |