Create an If statement based on a different query

Kate123

New member
Local time
Today, 17:01
Joined
Feb 12, 2008
Messages
9
Hi

I am trying to write some code for after update on a form. I have created a serparate query (Query2) which differs from the one that the form is based on (Query1) and I want to use this to create an if statement.

I don't know how to write this in VBA.

In simple terms it would read.

If Query2.Expr1>0 Then msgbox "text" Else DoCmd.Close

Can anyone help me with correct code???
 
Hi

I am trying to write some code for after update on a form. I have created a serparate query (Query2) which differs from the one that the form is based on (Query1) and I want to use this to create an if statement.

I don't know how to write this in VBA.

In simple terms it would read.

If Query2.Expr1>0 Then msgbox "text" Else DoCmd.Close

Can anyone help me with correct code???

Off the top of my head, not tested:

In your AfterUpdate event

Code:
Docmd.openquery "Query2"
if query2!expr1 > 0 then
 msgbox "text"
else
 Docmd.Close
End if
 
That does not work. It does not recognise: If Query2!Expr1 > 0 Then
 
Code:
dim rs as recordset

set rs = currentdb.openrecordset(query2)

if rs!expr1 > 0 then
 msgbox "text"
else
 Docmd.Close
End if
 

Users who are viewing this thread

Back
Top Bottom