If Statement

mixedguy

Registered User.
Local time
Yesterday, 23:55
Joined
Jun 12, 2002
Messages
52
In a grouped toggle button I'm trying to write an If statement that opens up different reports depending on the toggle button selected.

example of my If Statement that doesn't work.
Plz help. Thanks in advance!

Private Sub Command25_Click()

If Me.BusSize = True Then
DoCmd.OpenReport "rptBus_Size", acViewPreview, , StrWhere
End If

If Me.ContMeth = True Then
DoCmd.OpenReport "rptContMethod_Init", acViewPreview, , StrWhere
End If

End Sub
 
You would be better off interrogating the option group “Value” and using a “Case” statement to process the result:

Select Case optYourOptionGroupName ' Your option group.
Case 1
DoCmd.OpenReport "rptBus_Size", acViewPreview, , StrWhere

Case 2
DoCmd.OpenReport "rptContMethod_Init", acViewPreview, , StrWhere

Case Else ' Other values.
Msgbox “Case Error”

End Select
 
Case Statement...

Hi Tony,

I'm not very familiar with VB code. Based on your response this is what came up with.

Select Case Frame45
Case1
DoCmd.OpenReport "rptBus_Size", acViewPreview,,StrWhere
End If

What should I put at "Case1?"

Thanks!
 
Case1...

Help...Select Case Statements are used to check for multiple conditions. How does the code understand whether it should run Case 1 or Case 2? There's no conditional statement indicating which case it should run.

Thanks!
 
Tony gave you the exact code you need. All that needs to be done is to replace "optYourOptionGroupName" with the actual name of your option group.

Select case statements evaluate the value of a field. In this case the field being evaluated is your option group. When the option group control value is 1, rptBus_Size will run/ When it is 2, rptContMethod_Init will run. The Case Else handles the possibility that no option was selected.
 
Mixed,

If you built the option group with a wizard, then you have an
option group named "Frame1" for example. Access will control
these for you. Depending on which option you select the option
group will be assigned a value. Say 1 for the first report,
2 for the second ...

The options in the Select Case statement are not "Case1", it is
The word Case, followed by a space, then followed by a value.
Yours will be "Case 1", "Case 2", etc.

You need the space.

You also need the Case Else for when they don't choose anything.

Wayne
 

Users who are viewing this thread

Back
Top Bottom