I have a button to print a report based on a forms current data, but it isn't working.

I am using a nav form to navigate between my data entry forms. when the form in question is opened under the nav form the button produces reports with no data. if I open the form independently sometimes it works and sometimes not. I opened independently and not in data entry mode it works great. Coding is as follows:

Private Sub Command23_Click()
DoCmd.OpenReport "Produced Water Ticket Data", acViewReport, , "[Ticket Number]=" & Me.[Ticket Number]
DoCmd.OpenReport "Produced Water Ticket Data SWD", acViewReport, , "[Ticket Number]=" & Me.[Ticket Number]
End Sub
There are two different reports listed that are supposed to draw from the same form. What am I missing?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeffrey CoachmanMIS LiasonCommented:
Try saving the records before opening the report(s)

   DoCmd.RunCommand acCmdSaveRecord

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeffrey CoachmanMIS LiasonCommented:
...if you create a new record (new ticket number)
...and immediately click the Print button, ...the Form's after update event may not have triggered, ...hence the code can't filter for a record (Ticket Number) that is not "commuted" (saved) yet...

There is code that uses the "Dirty" property to save the record, ...but I like referring to:
...for examples here, because it is easy to understand what it does...

Lets see what other Experts may post...
ADuke73Author Commented:
Thank you Jeffrey. I inserted that line and with the form in data entry it works great! But when I open it through the navigation form I get this:
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

You are getting the popup because you are referring to a form that is not open.
ADuke73Author Commented:
Pat, your comment brought to my attention, where in desperation, I had gone into the reports data query and added criteria. Since reading your comment I cleared that criteria and it works perfectly.
Jeffrey CoachmanMIS LiasonCommented:
See Pat's comment
...it could also be that you spelled one of the names wrong,...so check your spelling carefully.

Did this code ever work?

AFAICT, you should be able to simplify the code to something like this:
DoCmd.OpenReport "Produced Water Ticket Data", acViewNormal, , "[Ticket Number]=" & Me.[Ticket Number]
DoCmd.Close acReport, "Produced Water Ticket Data"
DoCmd.OpenReport "Produced Water Ticket Data SWD", acViewNormal, , "[Ticket Number]=" & Me.[Ticket Number]
DoCmd.Close acReport, "Produced Water Ticket Data SWD"

Open in new window

ADuke73Author Commented:
But where is the print command?
Jeffrey CoachmanMIS LiasonCommented:
the argument:  ViewNormal
...is the default, ...and will Print the Report...

God only knows why they did not call it "PrintReport"


Give it a try...
ADuke73Author Commented:
That would make more sense. Thanks Jeffrey!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.