Print Records Errors

J

Jessica

This is my very simple code to print certain records from a form:

Private Sub cmbMassPrint_Click()
On Error GoTo Err_cmbMassPrint_Click

Dim StartPage, EndPage As Long

StartPage = InputBox("What record number [not ID!] do I start from?",
"Print Range")
EndPage = InputBox("What record number [not ID!] do I end at?", "Print
Range")

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.PrintOut acPages, StartPage, EndPage

Exit_cmbMassPrint_Click:
Exit Sub

Err_cmbMassPrint_Click:
MsgBox Err.Description
Resume Exit_cmbMassPrint_Click

End Sub

I originally had:
Dim StartPage, EndPage As Integer
but this produce an overflow error when we reaches over 32767 records.

So I changed it to:
Dim StartPage, EndPage As Long

and now I get this error message:
An expression you entered is the wrong data type for one of the arguments.

You tried to run a macro or use a method to carry out an action, but an
expression evaluated to the wrong data type. For example, for the Close
method you specified a string for the Object Type argument, but this argument
can be set only to certain intrinsic constants or their numeric equivalents.

Help! please...

~Jessica
 
J

Jessica

Thanks for the tips.

Here is my new code:

Private Sub cmbMassPrint_Click()

Dim strStartPage, strEndPage As String
Dim lngStartPage, lngEndPage As Long

Do
strStartPage = InputBox("What record number [not ID!] do I start
from?", "Print Range")
If IsNumeric(strStartPage) = True Then
lngStartPage = CLng(strStartPage)
Exit Do
End If
If MsgBox("Invalid input", vbRetryCancel) = vbCancel Then Exit Sub
Loop

Do
strEndPage = InputBox("What record number [not ID!] do I end at?",
"Print Range")
If IsNumeric(strEndPage) = True Then
lngEndPage = CLng(strEndPage)
Exit Do
End If
If MsgBox("Invalid input", vbRetryCancel) = vbCancel Then Exit Sub
Loop

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.PrintOut acPages, lngStartPage, lngEndPage

End Sub

I am now getting this error message on the DoCmd.PrintOut line.

Run-time error 2498
An expression you entered is the wrong data type for one of the arguments
 
J

Jessica

Just to add...this code works if I input a record number under 32767. Is it
possible that you can't do a PrintOut with a Long Ingeger?
 
J

Jessica

Thanks, I did separate and define each variable separatly and I still get the
type mismatch error. I've decided to change the whole process to a report
prompted by dates or the ID field.

JimBurke via AccessMonster.com said:
Right, that's what I said in my original message - if the type isn't
sepcified it defaults to variant.

Dale_Fye said:
How did I miss that?

Actually, Access does allow it, and debugging does not catch it. I did the
following in a sub, and got these results

Dim StartPage, EndPage As Long
Debug.Print VarType(StartPage), VarType(EndPage)

Results: 0 (uninitialized), 3 (Long Integer)

When I then added a couple of lines, I got slightly different results

StartPage = 3
Debug.Print VarType(StartPage), VarType(EndPage)

Results: 2 (integer), 3 (Long Integer)

And when I did the following,

StartPage = #12/27/08#
Debug.Print VarType(StartPage), VarType(EndPage)

I got these results: 7 (date value), 3 (long integer)

So, it looks like if you do it this way, Access defines the variable as a
Variant

Dale
It's possible that it expects an integer, but did you read my earlier mesage?
You can't dim variables like this:
[quoted text clipped - 8 lines]
Just to add...this code works if I input a record number under 32767. Is it
possible that you can't do a PrintOut with a Long Ingeger?
 
J

Jessica

Thanks, I've decided to change the whole process to a report.

Dale_Fye via AccessMonster.com said:
Sorry, I NEVER use DoMenuItem, there are generally RunCommands for everything
available in DoMenuItem, and they are significantly easier to understand.
What is that line supposed to do?

And since I'm not familiar with Docmd.PrintOut, I looked it up in help. It
does not look like the PageFrom and PageTo are supposed to be "record
numbers" which is what your code implies. When I opened a table, and told it
to print from page 2 to page 2, it printed out 41 records starting at record
#43. When I added a command button to a continuous form, and used

DoCmd.PrintOut acPages, 2, 3

It printed out records 8-14 on one page and 15-21 on the next, indicating
that a "page" equates to the number of records (detail section of the form)
that will print out on a single sheet of paper. When I told it to print out
from page 45 to 45, it didn't print anything (I've only got about 100 records
in the table feeding this form), and did not generate an error.

HTH
Dale
Thanks for the tips.

Here is my new code:

Private Sub cmbMassPrint_Click()

Dim strStartPage, strEndPage As String
Dim lngStartPage, lngEndPage As Long

Do
strStartPage = InputBox("What record number [not ID!] do I start
from?", "Print Range")
If IsNumeric(strStartPage) = True Then
lngStartPage = CLng(strStartPage)
Exit Do
End If
If MsgBox("Invalid input", vbRetryCancel) = vbCancel Then Exit Sub
Loop

Do
strEndPage = InputBox("What record number [not ID!] do I end at?",
"Print Range")
If IsNumeric(strEndPage) = True Then
lngEndPage = CLng(strEndPage)
Exit Do
End If
If MsgBox("Invalid input", vbRetryCancel) = vbCancel Then Exit Sub
Loop

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.PrintOut acPages, lngStartPage, lngEndPage

End Sub

I am now getting this error message on the DoCmd.PrintOut line.

Run-time error 2498
An expression you entered is the wrong data type for one of the arguments

--
HTH

Dale Fye

Message posted via AccessMonster.com
 

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