Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing the value of a query in a variable

Status
Not open for further replies.

Davide77

Technical User
Mar 6, 2003
166
CH
Hallo,
I need to use the number of records there is in a query. I made a count query so I know the number of record. The problem now is how to store this number in a variable.

I'm using this code:

Dim RecordQuantitySQL As String

RecordQuantitySQL = "SELECT Count(qry_Room.Room) FROM [qry_Room];"

DoCmd.RunSQL RecordQuantitySQL

But I'm facing two problems: first of all my sql sentence seems to not be an sql sentence since the debugger tells me that the RunSQl Action needs a sql sentence.
The second problem is: after I run the query how can I store its value in a variable?

thanks
 
Use the Dcount function to count the records. Declare a Dim count as integer. Then write count=Dcount..... I have the code which I have written may be it will help u.

Private Sub Text2_AfterUpdate()
Dim stDocName As String
Dim stLinkCriteria As String
If DCount("[tool_barcode]", "qry_empcheckedout", "[tool_barcode]=[forms]![frm_checkout]![text2]") <> 0 Then
MsgBox "Cannot check out because this item has not beem checked in."
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top