How to reference query results in VB code

misslee1888

New member
Local time
Today, 15:02
Joined
Dec 2, 2002
Messages
98
I am looking to set a timmer on a form so that when the form opens, it looks to see the result of one of the queries in the db and sets the timmer so that if the result of the query is more that 0 then text flashed prompting user to take action(or a message box appears). If the result is < 0 then this will not happen.

Can anyone help

I thought

If Query.Query2.somefield.value > 0 Then
MsgBox "Do something"
End If

But this does not work. Can anyone help?
 
DAO Method

Code:
Dim myDB As DAO.Database
Dim qdfData As DAO.QueryDef
Dim rstData As DAO.Recordset

[color=green]'Set myDB[/color]
Set myDB = CurrentDb()

[color=green]'Check if Data Exists[/color]
Set qdfData= myDB.QueryDefs("qryData")
Set rstData = qdfData.OpenRecordset()
    
If rstData.RecordCount <> 0 Then
    [color=green]'Perform this code[/color]
End If

Set rstData = Nothing
Set qdfData = Nothing
Set myDb = Nothing

See here for more on using DAO and ADO in code.

See here for using .MoveLast. You don't really need to use it for your purposes since you just need to know whether or not the query returns any records but it's good to know why and how to use it.
 

Users who are viewing this thread

Back
Top Bottom