A little problem with Msg Box not appearing

Mansoor Ahmad

Registered User.
Local time
Today, 01:01
Joined
Jan 20, 2003
Messages
140
Dear All

Can somebody tell me what is wrong with the following statement. It is not working.

Case 1
myInt = Forms![New form Sample]!Cbpartno
If IsNull(Forms![New form Sample]!CbCustomer) Then
MsgBox ("Please select Customer first")
Else
DoCmd.OpenForm "F_Formview", acNormal, , "[CUSTOMER] = '" & myInd & "' And [PART NO] = '" & myInt & "'"
End If

Thanks
 
How is it not working?

myInd is not defined. Did you mean to use myInt?
 
Thank for the reply

myInd is defined. I actually copied only a part of the full code and it left out.

By 'not working' I mean that it does not display msg box. Nothing happens whne I click on command button.

What I want to do is that if nothing is selected in CmbCustomer, display the msgbox.

If I run without Msgbox statement, it works fine.
 
There's nothing wrong with the syntax of your If-Then-Else or your MsgBox statement.

I have reproduced your code (including the brackets) and it works fine for me.

I guess it's elsewhere in your code. When you say it works without the MsgBox statement, have you removed the If statement too? Post the code, please.
 
Her is the code

Private Sub Cmdformview1_Click()
viewresults acPreview

End Sub


Sub viewresults(PrintMode As Integer)
On Error GoTo Err_Cmdformview1_Click
'This procedure used in View_Report_Click and ......Sub procedures.
'Previews report selected in the frOverallqueries option group.

Dim myInt As String
Dim myInd As String
myInd = CbCustomer
Select Case Me!frmRelativequeries1
Case 1
myInt = Forms![New form Sample]!Cbpartno
'If IsNull(Forms![New form Sample]!CbCustomer) Then
'MsgBox ("Please select Customer first")
'Else
DoCmd.OpenForm "F_Formview", acNormal, , "[CUSTOMER] = '" & myInd & "' And [PART NO] = '" & myInt & "'"
'DoCmd.OpenReport "Report3", acViewPreview, , "[CUSTOMER] = '" & CbCustomer & "' And [PART NO] = '" & myInt & "'"
'DoCmd.OpenReport "Report3", acViewPreview, , "[PART NO] = '" & myInt & "'"
'End If
Case 2
myInt = Forms![New form Sample]!Cbliabcat
DoCmd.OpenForm "F_Formview", acNormal, , "[CUSTOMER] = '" & myInd & "' And [CAT] = '" & myInt & "'"
'DoCmd.OpenReport "Report3", acViewPreview, , "[CUSTOMER] = '" & myInd & "'" And "[CAT] = '" & myInt & "'"

Case 3
myInt = Forms![New form Sample]!Cbcustomerdefcode
DoCmd.OpenForm "F_Formview", acNormal, , "[CUSTOMER] = '" & myInd & "' And [REJ CODE] = '" & myInt & "'"

End Select

'DoCmd.Close acForm, "New form Sample"

Exit_Cmdformview1_Click:
Exit Sub

Err_Cmdformview1_Click:
Resume Exit_Cmdformview1_Click

End Sub

Thanks
 
I don't think its the message box but the If statement that is is problem.

I know you can nest Case statements, but I suspect you can't nest an If statement in a Case statement. You could replace the If with a Case.
 
Neileg

Thank you for the reply. I think I would remove the msgbox from the code and make sure that nobody leaves customer combo box blank before chosing an option.

Now while I am here and the code is there and you are being very helpfull as usual, I am stuck in another problem as well.

I have pasted that problem in the same forum earlier on. But from one of your comments in your last reply about nesting, made me realize that probably my solution may be there.

Can you please explain me how you nest in Case statements?

If I have not understood incorrectly, it would mean that if I have got option1 selected then in Case1 statement I can create more cases e.g. I can put 5 Docmd statements (similar to above code) each opening different report? If that is the case then that is what I want to know.

Looking forward to your reply.
 
Sorry, I can't help with nested Case statements, as I have never used them! There are examples in the help files, though.
 
Select Case Me!frmRelativequeries1
If IsNull(Forms![New form Sample]!CbCustomer) Then
MsgBox ("Please select Customer first")
Exit Sub
End If

Case 1
myInt = Forms![New form Sample]!Cbpartno
 
I have tried today and it prompted

'Statments and labels invalid between Select case and first case'
 
If IsNull(Forms![New form Sample]!CbCustomer) Then
MsgBox ("Please select Customer first")
Exit Sub
End If
Select Case Me!frmRelativequeries1
Case 1
myInt = Forms![New form Sample]!Cbpartno
 

Users who are viewing this thread

Back
Top Bottom