Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Tickets with a button on a form. PLEASE HELP

Status
Not open for further replies.

THEJOESTER

Technical User
Jul 6, 2006
39
US
Hi I hope someone can help me with this. I need to be able to print tickets when i enter information into the form. I want to be able to print selected information from the form on the tickets. For example: if a group purchases 3 adults and 2 children for the 10:00 train i need 5 tickets to print saying 1 adult 10:00, 1 adult 10:00, 1 adult 10:00, 1 child 10:00, 1 child 10:00. Is this possible. If it is can someone help me.
 
I'm assuming you're storing the number of tickets purchased somewhere in a table? What does the structure of your table look like, and what would the records look like for your example (3 adults, 2 children for the 10:00 train)?
 
My table has three colunms # of Adults, # of children, and # of Seniors. If i put my example in the form, the adults column would have 3 and the child column would have 2 and the senior column would have 0, or be blank.

Any more details just ask.
 
I'm going to assume you want to print these tickets from the data entry screen. On your screen, you probably have fields representing the # of adults, children, and seniors. I'm also going to assume you have already created your "Ticket" reports. In the "Print tickets" button OnClick event, try this code...
Code:
Dim i as integer
Dim j as integer
Dim k as integer

For i = 1 to CInt(txtAdults.Text)
   DoCmd.OpenReport ("AdultTicket")
Next

For j = 1 to CInt(txtChildren.Text)
   DoCmd.OpenReport ("ChildTicket")
Next

For k = 1 to CInt(txtSenior.Text)
   DoCmd.OpenReport ("SeniorTicket")
Next

Also, if you have the Train Time in a field on your form, and you want that to print on the ticket, you could always pass that in as the OpenArgs parameter (last parameter of your OpenReport call.

Good Luck!
 
You said something about "tickets" report. What do you mean by this
 
You will need to create reports that represent the Tickets. One for Adult Ticket, one for Child Ticket, and one for Senior Ticket. These reports will be what you want to print out.
 
When I try Making a report, the report prints out all the adults that are in the table. How do i prevent it from doing this and only printing the number on the record.
 
Did you use the report wizard to create your report? If so, delete your report and just create it in design view. Don't select a record source for your report.

You will need a report for Adult Ticket, a separate report for Child Ticket, and a third report for Senior Ticket. I will leave it up to you to format the report according to your needs.

Create your Ticket reports (one for Adult Ticket called "rptAdultTicket", one for Child Ticket called "rptChildTicket" and one for Senior Ticket called "rptSeniorTicket"), without using the wizard and without selecting a record source. Simply place a label on the report that reads "Adult Ticket" (or "Child Ticket" or "Senior Ticket"), and put a textbox control in the Detail section on the report and name it "txtTime". Then, on the Detail section's "On Format" event, put the following line of code...
Code:
Me.txtTime.Value = Me.OpenArgs

Back on your form, you should have 4 textbox controls and a button. The textbox controls are called, "txtAdult", "txtChild", "txtSenior", and "txtTime". The button is "btnPrint". In the "On Click" event of the btnPrint, you will put the following code...
Code:
Dim i as integer
Dim j as integer
Dim k as integer

For i = 1 to CInt(txtAdults.Text)
   DoCmd.OpenReport "rptAdultTicket", acViewPreview, , , , Me.txtTime.Value
Next

For j = 1 to CInt(txtChildren.Text)
   DoCmd.OpenReport "rptChildTicket", acViewPreview, , , , Me.txtTime.Value
Next

For k = 1 to CInt(txtSenior.Text)
   DoCmd.OpenReport "rptSeniorTicket", acViewPreview, , , , Me.txtTime.Value
Next
 
Hey i did this but once i click the button it gives me runtime error 2185 "you cant reference a property or method for a control unless the control has focus. Is there anyway to fix this, if there is can you please help me
 
runtime error 2185
Replace ALL .Text with .Value

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Should i replace them in the code or the text boxes. The text boxes dont have the extension .value.
 
Now it says error code 424 object required then it points to the whole line "for i=1...
 
Sorry it was my error it works. Thanks a lot, the only thing is, is it possible to skip the preview and just print it once you press the button or do you have to go through the preview?
THANKS A LOT GUYS!! :)
 
Replace acViewPreview with acViewNormal

Tip: when in VBE the F1 and F2 keys are very useful.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
This is a stupid question but im a beginner. Why would it be useful and what is VBE?
 
If i also wanted to put a date in there would i put this Me.txtTime.Value = Me.OpenArgs by the other open argument and then where would i put Me.Date.Value in the code for the button?

PS I already have a textbox named txtDate
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top