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!

Access IF THEN Question

Status
Not open for further replies.

ccepaulb

Technical User
Jan 29, 2004
89
US
I have a button on an Access form that when clicked runs a macro that echoes, runs a query and maximizes the window. Now I added an option group that has two check boxes. What I want to do is, when the button is now clicked it will run either macro1 or macro2 based on which check box is checked.
Macro1 would run a query that sorts on Field A and Macro2 would run a query that sorts on Field B.
I thought it would be easiest (not good with code )to create 2 separate queries and 2 macros that would run either choice. With that said, how would I add an IF THEN statement into a query.
So it would say... when button is clicked and check box 1 is checked, then run macro1 that runs query1, if check box 2 is checked, then run macro2 that runs query2.
I know some more seasoned Access uses are saying there is a better way, but without being very knowledgeable with writing code, that's the best I could think of
Any suggestions?

Thanks, Paul
 
I was playing around with something like this (doesn't work though)

Private Sub ViewDataButton_Click()

If ViewCheck1 = 1 Then
DoCmd.OpenQuery "ItemAcctVoids"
Else
DoCmd.OpenQuery "ItemAcctVoids2"
End If

End Sub
 
All right I'm getting closer, here is what I wrote
Private Sub ViewDataButton_Click()
Dim rptname As String
Dim qryname As String


Select Case Me.Frame1

Case 1 'Open ItemAcctVoids

qryname = "ItemAcctVoids"
DoCmd.OpenQuery qryname

Case 2 'Open ItemAcctVoids

qryname = "ItemAcctVoids2"
DoCmd.OpenQuery qryname

End Select
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top