Open Report OnClick

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

Guest

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!
 
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
____________________
 
Back
Top