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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run a query based on value in table

Status
Not open for further replies.

Bumpthis

IS-IT--Management
Nov 5, 2001
16
GB
Hi
I have an access 97 database which uses a form to collect either a yes or a no answer and then stores it in a table. The problem is i need to be able to run either query 1 if the response in the table is yes or query 2 if the response is no, using a button on another form (its needs to remain just the one button). How would i go about trying to do this, i have tried an if statement using the button click expression but with no success :-<

Many thanks in advance
 
In principle you can use a DLookup() function to determine what was saved.

If dLookup("[myfield]","mytable") = "Yes" then
'run query1
else
'run query2
end if

If you are using a Yes/No field then the test needs to be :
If dLookup("[myfield]","mytable") = True then

Obviously put your own table and fieldnames instead.
 
Thanks for the help but i keep getting a compile error message "argument not optional"

Private Sub Command5_Click()
On Error GoTo Err_Command5_Click

IIf DLookup("[tablename]![object]", "[tablename]") = "Yes"
Then
stDocName = "query1"
DoCmd.Openquery stDocName, acPreview
Else
stDocName = "query2"
DoCmd.Openquery stDocName, acPreview

End If

Exit_Command5_Click:
Exit Sub

Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click

End Sub
 
Sorry. My mistake.

The dlookup requires some criteria for the lookup. Such as:
IIf DLookup("[tablename]![object]", "[tablename]", "[ReciD] = 1") = "Yes"

I am assuming from your original post that theer is only one record on this table. So If it doesn't already have an id field create one and give it a value of 1 (default 1), primary key, required.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top