473,396 Members | 1,816 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,396 software developers and data experts.

How do I skip over a record in a query once the loop has gone through once?

anoble1
245 128KB
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.

Expand|Select|Wrap|Line Numbers
  1. 'Update Routine Feeders
  2. 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;"
  3.  
  4. Set HATTrecords = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges, dbOptimistic)
  5.  
  6. HATTrecords.MoveFirst
  7. CAMPrecords.MoveFirst
  8.  
  9. 'Update the records in HATT with CAMP records
  10. While Not HATTrecords.EOF
  11.     If Not CAMPrecords.EOF Then
  12.         If CAMPrecords("LOCATION_CODE") = HATTrecords("FeederNumber") Then
  13.             HATTrecords.Edit
  14.             HATTrecords("MilesBilled") = CAMPrecords("MilesBilled")
  15.             HATTrecords.Update
  16.             HATTrecords.MoveNext
  17.         End If
  18.         CAMPrecords.MoveNext
  19.     Else
  20.         CAMPrecords.MoveFirst
  21.     End If
  22. Wend
  23.  
  24. 'Close the recordsets
  25. HATTrecords.Close
  26. CAMPrecords.Close
  27.  
  28. DoCmd.Close acForm, "frmRunningQuery"
  29. MsgBox "Done"
  30.  
Feb 27 '12 #1
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.
Feb 27 '12 #2
anoble1
245 128KB
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.
Feb 27 '12 #3
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?
Feb 27 '12 #4
anoble1
245 128KB
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.
Feb 27 '12 #5
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).
Feb 27 '12 #6
Mihail
759 512MB
Assuming that the rest of your code is Ok this should do the job.

Expand|Select|Wrap|Line Numbers
  1.     'Update the records in HATT with CAMP records
  2.     HATTrecords.MoveFirst
  3.     Do While Not HATTrecords.EOF
  4.         CAMPrecords.MoveFirst
  5.         Do While Not CAMPrecords.EOF
  6.             If CAMPrecords("LOCATION_CODE") = HATTrecords("FeederNumber") Then
  7.                 'Update HATT
  8.                 HATTrecords.Edit
  9.                 HATTrecords("MilesBilled") = CAMPrecords("MilesBilled")
  10.                 HATTrecords.Update
  11.         Exit Do 'The match is find and can't be others
  12.             End If
  13.             CAMPrecords.MoveNext
  14.         Loop
  15.         HATTrecords.MoveNext
  16.     Loop
  17.  
  18.     'Close the recordsets
  19.     HATTrecords.Close
  20.     CAMPrecords.Close
  21.  
  22.     DoCmd.Close acForm, "frmRunningQuery"
  23.     MsgBox "Done"
I update your code in order to show you how can be done but using an update query is much much faster.
Feb 28 '12 #7

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

Similar topics

0
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...
1
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 =...
0
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
0
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...
19
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...
3
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...
5
abouddan
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...
4
by: sonal0228 | last post by:
how to retrive and display attendance of all students of a class subject wise using servlet
1
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...
1
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
jinu1996
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...
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,...

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.