Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using variables with the docmd.openreport

Status
Not open for further replies.

dpedley

Technical User
Apr 18, 2007
28
US
I'm trying to write code so that a user can open a form and pick a report from one list and a city from another. The form is working fine. But my problem is trying to get the right syntax to use the docmd.openreport. It should be simple

DoCmd.openreport test, acViewPreview, , "office_worked =" & testLoc

'test' being the variable holding the report name, and 'testloc' the Location.

This returns an empty set. When I tried simply replacing the variable with hard code. I got this to work.

DoCmd.openreport test, acViewPreview, ," [office_worked]= ""ATL"" "

ATL of course is the code for Atlanta. Works great. I have tried countless ways to substitute ""ATL"" with the 'testloc' variable, to no avail. Finally I created a small proc (below) which used only a dimmed value 'crit' to see what was coming out in my combination, and the Docmd statement. In several previous attempts I've gotten the 'crit' to come out looking identical to the statement above which works, but I still get an empty set. The code below is back to the beginning.

Private Sub Test_DblClick(Cancel As Integer)

Dim crit As String

crit = " [office_worked] =" & testLoc
DoCmd.OpenReport test, acViewPreview, , crit

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top