TYPE MISMATCH error in subroutine

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This code produces a TYPE MISMATCH error for strMode on both OpenReport
lines. The MsgBox return shows the parameters appear to be passed correctly.
What is wrong??

Call PrintScoreSheets(7, "Event Name", "acPreview")

Public Sub PrintScoreSheets(intEvent As Integer, strEvent As String, strMode
As String)

If intEvent <> 11 Then
'Print Score sheets
MsgBox intEvent & " " & strEvent & " " & strMode & " 2"
DoCmd.OpenReport "Score Sheets", strMode, "", ""
End If

If intEvent = 11 Then
MsgBox intEvent & " " & strEvent & " " & strMode & " 3"
'Print Duet Score sheets
DoCmd.OpenReport "Score Sheets (Duets)", strMode, "", ""
End If

End Sub

The following work-around works just fine from the same CALL as above so I
am fairly certain that the parameters are being passed correctly. HELP

Public Sub PrintScoreSheets(intEvent As Integer, strEvent As String, strMode
As String)

If (intEvent) <> 11 Then
'Print Score sheets
MsgBox intEvent & " " & strEvent & " " & strMode & " 2"
If strMode = "acNormal" Then
DoCmd.OpenReport "Score Sheets", acNormal, "", ""
End If

If strMode = "acPreview" Then
DoCmd.OpenReport "Score Sheets", acPreview, "", ""
End If
End If

If (intEvent) = 11 Then
'Print Score sheets
MsgBox intEvent & " " & strEvent & " " & strMode & " 3"
If strMode = "acNormal" Then
DoCmd.OpenReport "Score Sheets (Duets)", acNormal, "", ""
End If

If strMode = "acPreview" Then
DoCmd.OpenReport "Score Sheets (Duets)", acPreview, "", ""
End If
End If
 
Try and change the acPreview parameter to a number (2)

Call PrintScoreSheets(7, "Event Name", 2)

Public Sub PrintScoreSheets(intEvent As Integer, strEvent As String, strMode
As Integer)
 
No, don't do that. Just take the quotes from around acPreview when you make
the call and change strMode to intMode as Integer. Using the values of
intrinsic constants removes the value of using them. Who can remember that
acPreview = 2?
 
Hi Steve,

You're confusing literal strings "acNormal" and "acPreview" with the
constants acNormal and acPreview (which are defined in the Access object
model and whose values are respectively 0 and 2).

Try
... lngMode As Long)
...
DoCmd.OpenReport, "Score Sheets", lngMode
...


Call PrintScoreSheets(7, EventName, acPreview)
 
That is the right answer. I Knew acPreview is an intrinsic constant but by
passing it as a string caused the mismatch. I agree that constants are
easier to remember than numeric code values.

thank much

steve
 
Klatuu said:
No, don't do that. Just take the quotes from around acPreview when you
make
the call and change strMode to intMode as Integer. Using the values of
intrinsic constants removes the value of using them. Who can remember
that
acPreview = 2?

Me! Although I do regularly forget my wife's birthday.
 
Back
Top