"Type Mismatch" Error. (this time with the code)

N

Nadir

Hi,
I have this code below that works fine when clicking on OK but when
clicking on the "Cancel" button or the "X" to close I get the Type
Mismatch error. Help!

Thanks.


Option Compare Database
Option Explicit

Private Sub PrintByReport__Click()
On Error GoTo Err_PrintByReport__Click

Dim stDocName As String
Dim intUserRespond As Integer
Dim intReportNumber As Integer
Dim strWhere As String

If Me.Dirty Then 'save any edits
Me.Dirty = False
Else
intReportNumber = InputBox("Please enter the report number you
wish to print", "View BPL by report number")
strWhere = "[BPLReport] = """ & intReportNumber & """"
stDocName = "rptMasterBPLReport"
DoCmd.OpenReport stDocName, acViewPreview, , strWhere
intUserRespond = MsgBox("Do you want to print this report?",
vbOKCancel, "Print Report Window")
If intUserRespond = vbOK Then
DoCmd.PrintOut (acPrintAll)
Else
DoCmd.Close
End If
End If
Exit_PrintByReport__Click:
Exit Sub

Err_PrintByReport__Click:
MsgBox Err.Description
Resume Exit_PrintByReport__Click

End Sub
 
J

John Spencer (MVP)

You need to check to see if anything other than a zero-length string was
returned. Also, since Inputbox normally returns a string, I am surprised that
assigning the return value to IntReportNumber doesn't error. I assume that you
mean the OK and Cancel buttons on the Input Box.

Dim strReportNumber as String
....

Else
strReportNumber = InputBox("Please enter the report number you
wish to print", "View BPL by report number")

If IsNumeric(strReportNumber) = False then
Exit sub
Else
intReportNumber = CInt(strReportNumber)
...
 
N

Nadir

Thank you very much!!!

Nadir




John Spencer (MVP) said:
You need to check to see if anything other than a zero-length string was
returned. Also, since Inputbox normally returns a string, I am surprised that
assigning the return value to IntReportNumber doesn't error. I assume that you
mean the OK and Cancel buttons on the Input Box.

Dim strReportNumber as String
...

Else
strReportNumber = InputBox("Please enter the report number you
wish to print", "View BPL by report number")

If IsNumeric(strReportNumber) = False then
Exit sub
Else
intReportNumber = CInt(strReportNumber)
...

Hi,
I have this code below that works fine when clicking on OK but when
clicking on the "Cancel" button or the "X" to close I get the Type
Mismatch error. Help!

Thanks.

Option Compare Database
Option Explicit

Private Sub PrintByReport__Click()
On Error GoTo Err_PrintByReport__Click

Dim stDocName As String
Dim intUserRespond As Integer
Dim intReportNumber As Integer
Dim strWhere As String

If Me.Dirty Then 'save any edits
Me.Dirty = False
Else
intReportNumber = InputBox("Please enter the report number you
wish to print", "View BPL by report number")
strWhere = "[BPLReport] = """ & intReportNumber & """"
stDocName = "rptMasterBPLReport"
DoCmd.OpenReport stDocName, acViewPreview, , strWhere
intUserRespond = MsgBox("Do you want to print this report?",
vbOKCancel, "Print Report Window")
If intUserRespond = vbOK Then
DoCmd.PrintOut (acPrintAll)
Else
DoCmd.Close
End If
End If
Exit_PrintByReport__Click:
Exit Sub

Err_PrintByReport__Click:
MsgBox Err.Description
Resume Exit_PrintByReport__Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top