Subform printing report

  • Thread starter Thread starter sue gray
  • Start date Start date
S

sue gray

I have a subform that checks does some error checking in the Before UPdate
Event. I seem to have that working ok. What I want to be able to do now is
if the form passes all my error checks, I want to ask to print a report or
not? Also, If this is a new record will the report be blank? Do I have to
have some code to save the data, before printing. I'm not sure where to
start on this. THanks in advance
 
On Wed, 10 Dec 2008 13:11:04 -0800, sue gray

Good question. Access provides for this as follows:
* In the Form_BeforeUpdate perform your checks like you are already
doing. If you detect an error condition, set the Cancel argument to
True. This will prevent the record from being saved, so the user can
fix it and try again. E.g.:
private sub Form_BeforeUpdate(Cancel as Boolean)
if Me.FirstName = "Tom" then
Msgbox "Yo! That's an illegal name. Fix it!"
Cancel = True
end if
end sub

Then to run a report or perform any other action that depends on the
record being valid and saved, use the Form_AfterUpdate event:
private sub Form_AfterUpdate
DoCmd.OpenReport "myReport", WhereCondition:="CustomerID=" &
Me.CustomerID
end sub

-Tom.
Microsoft Access MVP
 
Thanks for the response. Is there a way to ask the user if they want to
print the report or not? Thanks again.
 
On Thu, 11 Dec 2008 07:23:03 -0800, sue gray

Sure:
private sub Form_AfterUpdate
if Msgbox("Wanna see the report?", vbQuestion or vbYesNo) = vbYes then
DoCmd.OpenReport "myReport", WhereCondition:="CustomerID=" &
Me.CustomerID
end if
end sub

-Tom.
Microsoft Access MVP
 
Back
Top