Type Mismatch question

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

Guest

I have the following code that is executed from a form that should print odd
or even pages but get a type mismatch at the Reports![Print...] command line.
What am I doing wrong?

Private Sub btnEvenOdd_Click()
Dim strRptName As String
Dim strPrompt1 As String, strPrompt2 As String
Dim strResponse As String
Dim strFullPrompt As String
Dim strTitle As String

strPrompt1 = "Enter Odd or Even to print the "
strPrompt2 = " Report"
strTitle = "Print Odd OR Event Paged Report"
strRptName = Me.lstReports
strFullPrompt = strPrompt1 & strRptName & strPrompt2

Select Case strRptName


Case "Testing"
strReponse = UCase(InputBox(strFullPrompt, "Print Reports"))
DoCmd.OpenReport "rptTesting", acViewPreview

If strResponse = Even Then
Reports![Print Odd Even Pages]![PrintPages] = "Even" And Page
Mod 2 = 1
DoCmd.Close "rptTesting"
Else
Reports![Print Odd Even Pages]![PrintPages] = "Odd" And Page Mod
2 = 0
DoCmd.Close "rptSongsByTitle"
End If

End Select



End Sub
 
If strResponse = Even
Is Even a variable? I think not. I think what you need is:
If strResponse = "Even"
 
Sorry, I had copied a previous version of the code. I also found the
misspelling of strResponse...never-the-less...

I still get the type mismatch message at the Reports![Print Odd Even
Pages]![PrintPages] = "Even" And Page Mod 2 = 1 lines.

Thanks


Klatuu said:
If strResponse = Even
Is Even a variable? I think not. I think what you need is:
If strResponse = "Even"

Wylie C said:
I have the following code that is executed from a form that should print odd
or even pages but get a type mismatch at the Reports![Print...] command line.
What am I doing wrong?

Private Sub btnEvenOdd_Click()
Dim strRptName As String
Dim strPrompt1 As String, strPrompt2 As String
Dim strResponse As String
Dim strFullPrompt As String
Dim strTitle As String

strPrompt1 = "Enter Odd or Even to print the "
strPrompt2 = " Report"
strTitle = "Print Odd OR Event Paged Report"
strRptName = Me.lstReports
strFullPrompt = strPrompt1 & strRptName & strPrompt2

Select Case strRptName


Case "Testing"
strResponse = UCase(InputBox(strFullPrompt, "Print Reports"))
DoCmd.OpenReport "rptTesting", acViewPreview

If strResponse = Even Then
Reports![Print Odd Even Pages]![PrintPages] = "Even" And Page
Mod 2 = 1
DoCmd.Close "rptTesting"
Else
Reports![Print Odd Even Pages]![PrintPages] = "Odd" And Page Mod
2 = 0
DoCmd.Close "rptSongsByTitle"
End If

End Select



End Sub
 
Your Mod statement is incorrect.

Pages]![PrintPages] = "Even" And 1 = Page Mod 2

Wylie C said:
Sorry, I had copied a previous version of the code. I also found the
misspelling of strResponse...never-the-less...

I still get the type mismatch message at the Reports![Print Odd Even
Pages]![PrintPages] = "Even" And Page Mod 2 = 1 lines.

Thanks


Klatuu said:
If strResponse = Even
Is Even a variable? I think not. I think what you need is:
If strResponse = "Even"

Wylie C said:
I have the following code that is executed from a form that should print odd
or even pages but get a type mismatch at the Reports![Print...] command line.
What am I doing wrong?

Private Sub btnEvenOdd_Click()
Dim strRptName As String
Dim strPrompt1 As String, strPrompt2 As String
Dim strResponse As String
Dim strFullPrompt As String
Dim strTitle As String

strPrompt1 = "Enter Odd or Even to print the "
strPrompt2 = " Report"
strTitle = "Print Odd OR Event Paged Report"
strRptName = Me.lstReports
strFullPrompt = strPrompt1 & strRptName & strPrompt2

Select Case strRptName


Case "Testing"
strResponse = UCase(InputBox(strFullPrompt, "Print Reports"))
DoCmd.OpenReport "rptTesting", acViewPreview

If strResponse = Even Then
Reports![Print Odd Even Pages]![PrintPages] = "Even" And Page
Mod 2 = 1
DoCmd.Close "rptTesting"
Else
Reports![Print Odd Even Pages]![PrintPages] = "Odd" And Page Mod
2 = 0
DoCmd.Close "rptSongsByTitle"
End If

End Select



End Sub
 
Reports![Print Odd Even Pages]![PrintPages] = "Even" And Page Mod 2 = 1

That statement attempts to evaluate
"Even" And Page Mod 2 = 1
and place the result in the control called PrintPages. I don't know what
you really want but I'm sure it's not that.

The type mismatch is generated because you are using the string "Even"
as an argument for the And operator, which requires a logical or numeric
value.
 
John,
The code you commented on was the line of code found on Microsofts site on
printing odd and even pages. The article's code refers to creating a macro (
and I assume this is the built in macro builder). I thought the same code
would/should run in a user defined macro. Still haven't got the code to print
odd even pages..

Thanks

John Nurick said:
Reports![Print Odd Even Pages]![PrintPages] = "Even" And Page Mod 2 = 1

That statement attempts to evaluate
"Even" And Page Mod 2 = 1
and place the result in the control called PrintPages. I don't know what
you really want but I'm sure it's not that.

The type mismatch is generated because you are using the string "Even"
as an argument for the And operator, which requires a logical or numeric
value.
 
In most Office applications, a macro is a VBA procedure. It's different
in Access, where for historical reasons macros are quite distinct from
VBA. What you have done is taken an expression that makes perfect sense
when used as the Condition argument of a macro, and put it into a VBA
procedure without any regard for the syntax.

Also, as far as I know the Microsoft articles (e.g.
http://support.microsoft.com/?kbid=209508) say
Forms![Print Odd Even Pages]![PrintPages]="Even" And Page Mod 2=1 which you have changed to
Reports![Print Odd Even Pages]![PrintPages] = "Even" And Page Mod 2 = 1

I'm not an expert on printing reports, but it looks as if the Microsoft
method is as good as any and I suggest you follow it. It will work as
described even if you are using code running in a form to open the
report; and in fact it relies on having a textbox on a form containing
"Odd" or "Even" (that's why it says
Forms![Print Odd Even Pages]![PrintPages]

John,
The code you commented on was the line of code found on Microsofts site on
printing odd and even pages. The article's code refers to creating a macro (
and I assume this is the built in macro builder). I thought the same code
would/should run in a user defined macro. Still haven't got the code to print
odd even pages..

Thanks

John Nurick said:
Reports![Print Odd Even Pages]![PrintPages] = "Even" And Page Mod 2 = 1

That statement attempts to evaluate
"Even" And Page Mod 2 = 1
and place the result in the control called PrintPages. I don't know what
you really want but I'm sure it's not that.

The type mismatch is generated because you are using the string "Even"
as an argument for the And operator, which requires a logical or numeric
value.
 
Back
Top