Basic VBA to open report based on field (1 Viewer)

miacino

Registered User.
Local time
Today, 03:28
Joined
Jun 5, 2007
Messages
106
I thought this would be a very basic VBA code. I'm trying to open a report, using a command button, based on a mutual field in the report and on the open form [positionID].
While it does open the report, it is not limiting the report to that specific [positionID].

---------------------
Private Sub Command553_Click()

If Me.PositionStatus.Value = "Per Diem" Then
DoCmd.OpenReport "Offer Packet_Cover PerDiem", acViewPreview, , [PositionID] = Me.[PositionID]
End If

End Sub
-----------------------------

:banghead:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:28
Joined
Oct 29, 2018
Messages
21,358
Hi. The Where Condition argument of the OpenReport method expects a String value. Try enclosing it with quotes. For example:
Code:
DoCmd.OpenReport "Offer Packet_Cover PerDiem", acViewPreview, , "[PositionID] = " & Me.[PositionID]
 

miacino

Registered User.
Local time
Today, 03:28
Joined
Jun 5, 2007
Messages
106
Yes, that's it! Thank you!
(I should have known that! ....I just got over 3 days in bed with the flu. I'm blaming my lapse on that!):D
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:28
Joined
Oct 29, 2018
Messages
21,358
Hi. No worries. We all make mistakes. Cheers!
 

Users who are viewing this thread

Top Bottom