VBA Report Criteria

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

I am hoping for a miracle worker out there. I have spent days trying to
figure out how to use the where clause to print one record for a report. I
can't think of anything else to try. Below was my final attempt.

The report is based on a query from two tables. My first thought was to
change the query, but writing out the SQL does away with the reason for
building a query. You would need to go and change the code every time
something changed about the query. I also looked at using QueryDef, but
this is very slow. Then I discovered that you could do this with a where on
the OpenReport, but I can't make it work.

Dim strRptName As String
Dim strWhere As String

strRptName = "rpt10576"
strWhere = ("LName = ' " & Me!txtLName & " '")
DoCmd.OpenReport strRptName, acViewPreview, , strWhere, acWindowNormal
 
You have extra spaces in your expression. It would expect a field value like
" VorDog ". Try:
strWhere = "LName = """ & Me!txtLName & """"
 
You are the Man. I thought that I had tried every combination, but I
obviously missed this one. It worked perfect. I can't thank you enough,
now I just have to go and pick-up my computer off of the front lawn.
 
Back
Top