Hidden Queries

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

I am looking to run a query in the background (unknown) of a form. This
query will be relitive to the data within the form. I then want to pull
the data from that query within a function.

Sorry, I am a newbe and would appreciate some help. While waiting, I am
going through the help menu and try to find it also.

Thank you in advance for your help.

Steve
 
Hi Steve,

There are several ways to do this. You can open a recordset using DAO (Data
Access Objects) or ADO (ActiveX Data Objects). Here is some very simple
code that opens and loops through a simple recordset using DAO.

Open the recordset (once)
Test for records (EOF and BOF are both true when empty),
Loop through stopping when the EOF condition is reached.
Inside the loop we do something with each record,
Move to the next record
Close the recordset
Destroy the object variables.

'Code starts here:

Public Sub WalkRecordset()
Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()
Set rst = db.OpenRecordset("Select * from Customers")
With rst
If Not (.EOF And .BOF) Then
Do Until .EOF
Debug.Print "Customerid:" & .Fields("Customerid")
.MoveNext
Loop
End If
.Close
End With
Set rst = Nothing
Set db = Nothing
End Sub
 
Back
Top