Open Report OnClick

R

Ripper

I am using the following code in the OnClick event to open a report using the
BoxID number that is in the cell.

DoCmd.OpenReport "rptBoxPrintout", acViewPreview, , "BoxID=" & "'" &
Me.BoxID & "'"

Simple right? I keep getting a Run-Time error 3464 Data type Mismatch in
Critera expression.

The field I am clicking is the AutoNumber field in a datasheet view of
tblBoxes. The BoxID is set to auto number. If I use the same code using
BoxName in the BoxName field, no problem (except you can name a box
anything).

I want to make sure the correct report opens and the BoxID is the primary
key. How do I get the report to open up using the primary key? It is
driving me crazy!
 
B

Baby Face Lee

Hi there,

As the BoxID is a number field, you don't need to include the apostrophes.
The code should read:

DoCmd.OpenReport "rptBoxPrintout", acViewPreview, , "BoxID=" & Me.BoxID

You only need apostrophes when you're quoting a string.

Regards,

Lee
____________________
 

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