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.PrintOut
DoCmd.Close
DoCmd.OpenReport "Produced Water Ticket Data SWD", acViewReport, , "[Ticket Number]=" & Me.[Ticket Number]
DoCmd.PrintOut
DoCmd.Close
End Sub
There are two different reports listed that are supposed to draw from the same form. What am I missing?
ADuke73Asked:
Who is Participating?
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
1

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:
    "acCmdSaveRecord"
...for examples here, because it is easy to understand what it does...

Lets see what other Experts may post...
1
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:
Capture.PNG
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

PatHartmanCommented:
You are getting the popup because you are referring to a form that is not open.
0
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.
0
Jeffrey CoachmanMIS LiasonCommented:
@ADuke73
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

0
ADuke73Author Commented:
But where is the print command?
0
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...
1
ADuke73Author Commented:
That would make more sense. Thanks Jeffrey!
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.