0
votes

I have a button in an Access 2007 Form with the on click VBA code as follows:

Private Sub Command53_Click()
    DoCmd.OpenReport "BolLSW", acViewNormal, , "[bolnum] = '" & [bolnum] & "'"
End Sub

Essentially this will open a report (based on which number you enter for bolnum when pressing the button) which has the same information as the form and then print it. However when the report prints it print all the records instead of just the one entered.

Is there a way to specify to only print the desired record?

To clarify: Bolnum is a unique field within the form that auto increments. Clicking the "Generate BoL" prompts a dialog box for you to enter the Bolnum to print. Upon entering 2, both record 1 and 2 will print.

2
Both the form and the report have the same record source. Which is a table called "BoL"Rynoc

2 Answers

0
votes

I'd try giving [bolnum] (between the 2 &, i.e. the variable ) a different name. I guess Access is taking the value of the current row - so the where-clause is always true.

0
votes

I've solved this by removing some of the quotes from

DoCmd.OpenReport "BolLSW", acViewNormal, , "[bolnum] = '" & [bolnum] & "'"

specifically:

removing

>'<" & [bolnum] >& "'"<

resulting in:

DoCmd.OpenReport "BolLSW", acViewNormal, 1, "[bolnum] = " & [bolnum]