PDA

View Full Version : Having problems with OpenArg



jason52388
01-04-2012, 12:03 PM
Here is the code i have so far



Private Sub Report_Open(Cancel As Integer)
Me.Filter = "SAE=" & Me.OpenArgs
Me.FilterOn = True
End Sub


Sub RunReport2()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT * FROM [SAE]", dbOpenDynaset)
msgtitle = ""
msgbody = ""
MyPath = "G:\Jason\Blueline\"

Do Until rst.EOF
saename = rst.Fields(1).Value
saeemail = rst.Fields(2).Value
MyFilename = "Blueline Report - " & saename
DoCmd.OpenReport "WIP", acViewPreview, , , , saename
DoCmd.OutputTo acOutputReport, "WIP", acFormatPDF, MyPath & MyFilename, True
DoCmd.SetWarnings False
DoCmd.SendObject acSendReport, "WIP", acFormatPDF, saeemail, , , msgtitle, msgbody, False
DoCmd.Close acReport, "WIP"
DoCmd.SetWarnings True
rst.MoveNext
Loop
End Sub

The docmd.openreport line is where I believe I am having a problem. What I am doing is cycling through a list of names, opening a report based on that name/filtering for that name in the query the report is based on, saving it to my hard disc and then emailing it out. I need this to be automated with no popups as I will be distributing 200+ reports. Currently as this code stands, I keep receiving a popup. It keeps displaying the saename value, lets say jason, as a parameter and asks me to enter a value. The image is attached. I don't know if this is by design but from what I understood, it should just pass the argument to the "on open" event for the report and filter for that. I'm not sure what I could be doing wrong. Also I was curious if I am able to have a space or a comma in the argument. I tried Jason Doe and Doe, Jason and got an error. When I use just the first name I don't get an error but i get the parameter popup for the first name. Any ideas? I am using Access 2007.

Thanks in advance,
Jason

jason52388
01-05-2012, 01:24 PM
Figured it out. Just making sure no one will waste their time trying to solve it.