VBA to refresh,reload,requery a report? (1 Viewer)

MsLady

Traumatized by Access
Joined
Jun 14, 2004
Messages
438
How do you refresh,reload,requery a report?
My report opens from a buttonclick on a form based on criteria on that form.

When i click to open the report multiple times and in each time changing the criteria on the phone, it doesn't refresh the report to the newly specified criteria. It still opens the report based on the very first selected criteria.
With a form it's just me.requery
How do you do this?
 

MsLady

Traumatized by Access
Joined
Jun 14, 2004
Messages
438
Jacob Mathai said:
try this:

DoCmd.Requery Command isn't available right now
Me.Refresh
Hi Jacob :)
I get errors on both lines.

DoCmd.Requery Command isn't available right now

Me.Refresh Data member not found
 

pbaldy

Wino Moderator
Staff member
Joined
Aug 30, 2003
Messages
33,651
You can't requery a report. You have to close and reopen it.
 

MsLady

Traumatized by Access
Joined
Jun 14, 2004
Messages
438
pbaldy said:
You can't requery a report. You have to close and reopen it.
But that's jsut what i am doing. when it reopens. it doesn't refresh the parameters received in the underlying query :(
 

Kempes

Registered User
Joined
Oct 7, 2004
Messages
327
it sounds like you need to save the changes to the table before refreshing the report.
Try this in the code that launches the report.

DoCmd.RunCommand acCmdSaveRecord
Docmd.requery
me.refresh

Hope it helps

Kempes
 

gemma-the-husky

Super Moderator
Staff member
Joined
Sep 12, 2006
Messages
13,873
if you are just closing the report and then reopening it, when are you changing the parameters that would affect the report. It seems that that is the problem - the base query isn't changing.

If you are testing, instead of opening the report just put

msgbox(dcount("*","myquery")) which will report how many records in the query instead of opening the report, until you work out why the base query isnt changing.
 

MsLady

Traumatized by Access
Joined
Jun 14, 2004
Messages
438
hiyaaaa!!


I got it to work.

I found the problem was with my reset button. i placed a button on the form, that resets all the values on the form that takes parameters for my report query. When i click that button:
It resets the value of my combobox, Me![cboDept] = "" and i have an afterupdate event on this combobox to update an invisible textbox with the deptId of the value in cboDept, so putting "" was an issue, as there is no deptId associated with "". When i changed it to Me![cboDept] = Null. It works perfectly!

So as gemma suggested, I placed MsgBox (DCount("*", "qryAttendanceRecords")) in the code that opens the report/query to research and found it...

Thanks gemma-the-husky :D
Thanks Kempes :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom