Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / February 2007

Tip: Looking for answers? Try searching our database.

One record at time

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stapes - 27 Feb 2007 11:31 GMT
Hi

Can I do a select like so: -

SELECT TM_InvoiceItemGroup.Field3, TM_CompContact.AcNo
FROM TM_InvoiceItemGroup LEFT JOIN TM_CompContact ON
TM_InvoiceItemGroup.Field3 = TM_CompContact.AcNo
WHERE (((TM_CompContact.AcNo) Is Null));

and then step through the record set one record at a time? For each of
these I must first check if a Company record exists, and if not create
it. Then create the Contact record (which is what the above query was
looking for.

Stapes
Stapes - 28 Feb 2007 11:52 GMT
> Hi
>
[quoted text clipped - 11 lines]
>
> Stapes

Hi Again.

Did nobody know the answer to this?

Stapes
Lior Montia - 28 Feb 2007 12:03 GMT
try this:

Dim dbs As Database
Dim qdf As QueryDef
Dim rst As Recordset
   Set dbs = CurrentDb
   Set qdf = dbs.CreateQueryDef("")
   qdf.sql = "SELECT TM_InvoiceItemGroup.Field3, TM_CompContact.AcNo
FROM TM_InvoiceItemGroup LEFT JOIN TM_CompContact ON
TM_InvoiceItemGroup.Field3 = TM_CompContact.AcNo
WHERE (((TM_CompContact.AcNo) Is Null))"
       Set rst = qdf.OpenRecordset(2, 512)
   rst.movefirst
   while not(rst.eof)
       xxxxxxxxx
       xxxxxxxxxxx
       rst.movenext
   wend

write your code to update instead of xxxxxxxxx

>> Hi
>>
[quoted text clipped - 17 lines]
>
> Stapes
Douglas J. Steele - 28 Feb 2007 12:03 GMT
You can step through any recordset using code like:

Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Dim strSQL As String

 strSQL = "SELECT TM_InvoiceItemGroup.Field3, " & _
   "TM_CompContact.AcNo " & _
   "FROM TM_InvoiceItemGroup " & _
   "LEFT JOIN TM_CompContact " & _
   "ON TM_InvoiceItemGroup.Field3 = " & _
   "TM_CompContact.AcNo " & _
   "WHERE (((TM_CompContact.AcNo) Is Null))"

 Set dbCurr = CurrentDb()
 Set rsCurr = dbCurr.OpenRecordset(strSQL)
 Do Until rsCurr.EOF
   ' do work here
   rsCurr.MoveNext
 Loop

Having said that, though, it's seldom efficient to loop through a recordset
in VBA if you can simply use a SQL query, and from the sounds of it, you
should be able to create an INSERT INTO query that simply generates the
necessary records. Unfortunately, you haven't given enough details for me to
actually write the SQL for you.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

>> Hi
>>
[quoted text clipped - 17 lines]
>
> Stapes
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.