Select Case Problem

Annabelle

Registered User.
Local time
Today, 11:03
Joined
Feb 20, 2003
Messages
32
I have a form which previews a report at the end by clicking a command button. I need the report being previewed to be determined by a choice during completion of the form.
Example:
If Brand = Harris Flotebote
Report to Preview = rpt_WindowSticker

If Brand - Nautic Star
Report to Preview = rpt_WindowSticker_NauticStar

The event procedure was working great when I had only one Window Sticker report. But now that I am needing a different report to preview (and ultimately print) for each different brand, I am experiencing a problem.

I am not getting an error from my event procedure. Presently when I click the Preview Window Sticker button at the end of the form, nothing happens. But I don't receive any errors.

Event Procedure -
Private Sub cmdView_Click()

On Error GoTo ErrorHandler

DoCmd.RunCommand acCmdSaveRecord

Select Case Brand 'Evaluate Brand
Case "Harris_Flotebote"
DoCmd.OpenReport ReportName:="rpt_WindowSticker", _
View:=acViewPreview, _
WhereCondition:="ID=" & Me!ID
Case "Nautic_Star"
DoCmd.OpenReport ReportName:="rpt_WindowSticker_NauticStar", _
View:=acViewPreview, _
WhereCondition:="ID=" & Me!ID

End Select

ExitProcedure:

Exit Sub

ErrorHandler:

Select Case Err.Number

Case Else

MsgBox "Error # " & Err.Number & ": " & Err.Description, vbOKOnly + vbExclamation, "Unexpected Error"

End Select

Resume ExitProcedure

End Sub

Please help if you can.

Barbara
 
Please know I am not real knowledgeable on select case statements but I believe this is a way to achieve what I need.
 
Annabelle,

Where you have entered Case "Harris_Flotebote" change this to Case Is = "Harris_Flotebote" .

Similarly on each case statement include the "Is =" bit and it should sort out your problems.

Flyer
 
Even just the = is fine, the IS Keyword is put in automatically by the VB Editor.

The only time you can expect to use Case this or Case that is when dealing with enumerated constants.

i.e

Code:
Select Case WeekDay(Date)
    Case vbSunday
    Case vbMonday
    Case vbTuesday
    Case vbWednesday
    Case vbThursday
    Case vbFriday
    Case vbSaturday
End Select

If you were to use the actual value of those constants then:

Code:
Select Case WeekDay(Date)
    Case Is =1
    Case Is = 2
    Case Is = 3
    Case Is = 4
    Case Is = 5
    Case Is = 6
    Case Is = 7
End Select
 
Does this mean I should not be using a Select Case statement?
All I need to do is get the right report to preview based on which Brand is selected on the form.
 
Annabelle said:
Does this mean I should not be using a Select Case statement?
All I need to do is get the right report to preview based on which Brand is selected on the form.

You have it. Just do what R6Flyer says.
 
FYI - The brand is selected from a combox box and all data selected in the form is sent to a table called tbl_Inventory_Main.
 
Then are you referencing the correct column of the combo box?

i.e.

Select Case MyCombo.Column(0) would evaluate the value in the first column

Select Case MyCombo.Column(1) would evaluate the value in the second column

Select Case MyCombo.Column(n-1) would evaluate the value in the nth column
 
Thank you so much for all the help. My problem has been fixed.
 

Users who are viewing this thread

Back
Top Bottom