IF OK, Case Not OK

pepegot

Registered User.
Local time
Today, 06:28
Joined
Feb 20, 2006
Messages
39
I have an Option Box that contains three Report Choices, Report1, Report2 and Report3. I want to run the Reports. I coded using If-Then and it worked out fine. See code below:

Private Sub Frame0_Click()
If Me.Frame0 = 1 Then
DoCmd.OpenReport "Report1", acViewPreview
ElseIf Me.Frame0 = 2 Then
DoCmd.OpenReport "Report2", acViewPreview
Else
Me.Frame0 = 3
DoCmd.OpenReport "Report3", acViewPreview
End If
End Sub

I would like to get the same result using "Case." However, when I use the Case format, it does not show all the reports as it does in the IF -Then format. See Case format below:

Private Sub Frame1_Click()
Dim Test As Integer

Select Case Test

Case Me.Frame1 = 1
DoCmd.OpenReport "Report1", acViewPreview

Case Me.Frame1 = 2
DoCmd.OpenReport "Report2", acViewPreview

Case Me.Frame1 = 3
DoCmd.OpenReport "Report3", acViewPreview
End Select
End Sub

Something simple is missing at the top. Please advise as to how to correct this?
 
pepegot said:
I have an Option Box that contains three Report Choices, Report1, Report2 and Report3. I want to run the Reports. I coded using If-Then and it worked out fine. See code below:

Private Sub Frame0_Click()
If Me.Frame0 = 1 Then
DoCmd.OpenReport "Report1", acViewPreview
ElseIf Me.Frame0 = 2 Then
DoCmd.OpenReport "Report2", acViewPreview
Else
Me.Frame0 = 3
DoCmd.OpenReport "Report3", acViewPreview
End If
End Sub

I would like to get the same result using "Case." However, when I use the Case format, it does not show all the reports as it does in the IF -Then format. See Case format below:

Private Sub Frame1_Click()
Dim Test As Integer

Select Case Test

Case Me.Frame1 = 1
DoCmd.OpenReport "Report1", acViewPreview

Case Me.Frame1 = 2
DoCmd.OpenReport "Report2", acViewPreview

Case Me.Frame1 = 3
DoCmd.OpenReport "Report3", acViewPreview
End Select
End Sub

Something simple is missing at the top. Please advise as to how to correct this?

Code:
Private Sub Frame1_Click()
Dim Test As Integer

Select Case Test

Case Me.Frame1 = 1
DoCmd.OpenReport "Report1", acViewPreview

Case Me.Frame1 = 2
DoCmd.OpenReport "Report2", acViewPreview

Case Me.Frame1 = 3
DoCmd.OpenReport "Report3", acViewPreview
End Select
End Sub

I may be off base here, but the item you are working with should be listed in the Select Case at the top.

Shouldn't that be

Code:
Sub Frame1_Click()

Select Case Me.Frame1
Case 1
DoCmd.OpenReport "Report1", acViewPreview
Case 2 
DoCmd.OpenReport "Report2", acViewPreview
Case 3
DoCmd.OpenReport "Report3", acViewPreview
End Select
End sub

I may be completely off, but it can't hurt to try.
 
If -Then Ok Case NO

Selena,

I just tried it out and it works fine. I came to the same conclusion after submitting this post. We both agree and it works. Thanks for your quick reply. I knew it was something simple.

Private Sub Frame1_Click()


Select Case Me.Frame1

Case Is = 1
DoCmd.OpenReport "Report1", acViewPreview

Case Is = 2
DoCmd.OpenReport "Report2", acViewPreview

Case Is = 3
DoCmd.OpenReport "Report3", acViewPreview
End Select

End Sub
 
pepegot said:
Selena,

I just tried it out and it works fine. I came to the same conclusion after submitting this post. We both agree and it works. Thanks for your quick reply. I knew it was something simple.

Private Sub Frame1_Click()


Select Case Me.Frame1

Case Is = 1
DoCmd.OpenReport "Report1", acViewPreview

Case Is = 2
DoCmd.OpenReport "Report2", acViewPreview

Case Is = 3
DoCmd.OpenReport "Report3", acViewPreview
End Select

End Sub

Most welcome, and thank you for your reply back as to what you did to correct it. That helps others in the future.
 

Users who are viewing this thread

Back
Top Bottom