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

JimBurke via AccessMonster.com

You need to change the dim statement to

Dim StartPage as long, EndPage As Long

You have to specify the type for each variable, otherwise it will default (I
think the default is variant), which it did for StartPage. Hopefully that
will take care of it. I'm surpirsed that Access didn't convert it for you,
though.
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
 
D

Dale_Fye via AccessMonster.com

Jessica,

Cannot say I've ever used this technique. Whenever I want to print out a
record, I generally create a report.

However, the InputBox function returns a string value, so that is probably
where your problem is coming. I'd declare a string variable, set the value
of it using the inputbox, and then confirm that the value is actually numeric
before I tried to set the value of the long integer variable. Something like:


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
endif
if msgbox("Invalid input", vbRetryCancel) = vbCancel then Exit Sub
Loop

'do the same for strEndPage
'put your other code here

end sub

HTH
Dale
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?
 
D

Dale_Fye via AccessMonster.com

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
 
J

JimBurke via AccessMonster.com

It's possible that it expects an integer, but did you read my earlier mesage?
You can't dim variables like this:

Dim strStartPage, strEndPage As String

You have to specify the type for every variable listed - you can't specify
the type only at the end of your list. This may work in other languages but
not in VBA. I don't know that that's casuing your problem, but you still
should change any dim statements you have specified this way.
 
D

Dale_Fye via AccessMonster.com

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
 
J

JimBurke via AccessMonster.com

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]
 
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
 
D

Dale_Fye via AccessMonster.com

I'm glad that I've convinced you of that. Forms are really not designed to
be printed. Besides, one of the areas where Access really shines (over other
database applications) is its reporting capabilities.

If you need any help with that, just post back.

Dale
Thanks, I've decided to change the whole process to a report.
Sorry, I NEVER use DoMenuItem, there are generally RunCommands for everything
available in DoMenuItem, and they are significantly easier to understand.
[quoted text clipped - 55 lines]
 
J

JimBurke via AccessMonster.com

Stupid me, it never registered that you were printing form records. I'm
really slipping lately. Glad Dale talked you out of that!
Thanks, I've decided to change the whole process to a report.
Sorry, I NEVER use DoMenuItem, there are generally RunCommands for everything
available in DoMenuItem, and they are significantly easier to understand.
[quoted text clipped - 55 lines]
 

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