Compile Error: Variable not defined

  • Thread starter Thread starter johnlute
  • Start date Start date
J

johnlute

The debugger is pointing to "Cancel" in the following:

If IsNull(Me.cbSelectReport) = True Then
MsgBox "No document is selected!" & vbCrLf & _
"Select a document and click the PDF button.", vbOKOnly + _
Cancel = True
DoCmd.GoToControl "cbSelectReport"
Exit Sub
End If

I'm using Access 2003. I use this code in two separate databases. It
works in one but not the other. Any ideas???

Thanks!
 
johnlute said:
The debugger is pointing to "Cancel" in the following:

If IsNull(Me.cbSelectReport) = True Then
MsgBox "No document is selected!" & vbCrLf & _
"Select a document and click the PDF button.", vbOKOnly + _
Cancel = True
DoCmd.GoToControl "cbSelectReport"
Exit Sub
End If

I'm using Access 2003. I use this code in two separate databases. It
works in one but not the other. Any ideas???

Thanks!

Which event is the code in?

Keith.
www.keithwilby.co.uk
 
Which event is the code in?

Keith.www.keithwilby.co.uk

Hi, Keith. Thanks for the reply. Here's the full code from one
particular button:

Private Sub Preview_Click()
If IsNull(Me.cbSelectReport) = True Then
MsgBox "No document is selected!" & vbCrLf & _
"Select a document and click the Preview button.", vbOKOnly + _
Cancel = True
DoCmd.GoToControl "cbSelectReport"
Exit Sub
End If

On Error GoTo Err_Preview_Click
Dim i As Integer
Dim strForm As String

For i = 1 To CurrentProject.AllForms.Count
If CurrentProject.AllForms(i - 1).IsLoaded Then
strForm = CurrentProject.AllForms(i - 1).Name
If strForm <> "Marzetti Main Menu" Then
DoCmd.Close acForm, strForm, acSaveNo
End If
End If
Next i

Dim stDocName As String
Dim strWhere As String
strWhere = "[txtProfileID] = """ & _
Forms![Marzetti Main Menu].Form![txtProfileID] & """"
DoCmd.OpenReport Me!cbSelectReport, acPreview _
, , strWhere

Exit_Preview_Click:
Exit Sub

Err_Preview_Click:
MsgBox Err.Description
Resume Exit_Preview_Click

End Sub

The above in one database works fine. In anotehr database it does not!
 
There's no Cancel event associated with "Private Sub Preview_Click()" nor is
it declared anywhere. I assume that in the "other" database this code is in
an event such as an Open event "Private Sub Form_Open(Cancel As Integer)".

Keith.
www.keithwilby.co.uk
 
johnlute said:
The debugger is pointing to "Cancel" in the following:

If IsNull(Me.cbSelectReport) = True Then
MsgBox "No document is selected!" & vbCrLf & _
"Select a document and click the PDF button.", vbOKOnly + _
Cancel = True

Did you mean to have "+ _" at the end of the second last line above?

BTW I always indent when using & _ so it would make this more obvious
what you meant.
MsgBox "No document is selected!" & vbCrLf & _
"Select a document and click the PDF button.", vbOKOnly + _
Cancel = True
or

MsgBox "No document is selected!" & vbCrLf & _
"Select a document and click the PDF button.", vbOKOnly
Cancel = True

Tony
 
Back
Top