Full Version: printing forms
UtterAccess Forums > Microsoft® Access > Access Forms
billiken0505
hello everyone:
How do i print a form, only printing one record on each page???????????????
right now i have it printing out fine but every record is printed(one after another).
I just want to print the record that is on the screen.
any ideas????
crc
freakazeud
You might want to concider reports!!
Forms are not for printing! Reports are. Then you can manipulate everything in reports to print whatever you want to.
billiken0505
OK I FIGURED IT OUT........YOU JUST HAVE TO CHOOSE TO PRINT THE SELECTED RECORD
freakazeud
Are you still printing out forms? If yes then you doing it wrong. Forms are not meant for printing!!
Although you can print a form, that is not what it was designed for. The report gives you much more flexibility.
Pantherfan
How do you make a report print the current record of a form. Mine always go to the 1st record. How do I get it to print the current record from the form, and only that record??
Craig_Pettit
Hi, and welcome to utter access.
You need to make the control source for your report a query. Ie, if you use the table as your control source, it will show all of your records as you are finding now, but if you use a query or the query builder you can filter out the record you want based on certain criteria.
If you create the report and then put a command button on the form, you should be able to use the wizard to get the button to open the report and only show you the current record based on one of the fields on the form.
Make the criteria in the query as follows.
forms![your form name]![your field that contains the unique identifier]
This should do what you are looking for. Feel free to ask more questions if I have confused you.
HTH
Craig.
Pantherfan
OMG! Thanks..That worked..I was struggling with this for a week and a half..reading help files and tutorials and could'nt figure it out. THnaks allot Craig!
Craig_Pettit
No worries...
Glad to be a help.
Craig.
Pantherfan
ooops..wait a sec crag..I spoke too soon. I must have looked at the wrong thing because it's still returning the 1st label in my report and printing just that one.
Can you simplify it and tell me what I need to have?
What im doing is making a form that data will be entered into. There is a print button on the form, when someone clicks the button, i want it to print the info from the form that they just completed (as a report, so I can print as labels). It needs to print the current record after they enter the info and hit the print data.
Ounderstand the query part but it still is not right
any help will be appreciated..
Thanks
Craig_Pettit
What happens if you run the query without having the form open?
Pantherfan
same thing..
but strangely, my query in datasheet view only shows one record..and that one is always the very 1st record of my form.
Craig_Pettit
Can you copy the SQL from the query and post it here?
I'm a bit stumped, I might be able to pick it out of the sql...
Pantherfan
how do i get that? (the sql from query)..sorry im noobish
Craig_Pettit
in the query design view, click on view and select sql.
You can go back to design view by clicking view and design view.
Pantherfan
SELECT TOP 1 [H-Cell test].[Associate ID], [H-Cell test].[Header Type], [H-Cell test].[Header Description], [H-Cell test].[Product ID], [H-Cell test].[Header size], *
FROM [H-Cell test]
WHERE ((([H-Cell test].[Product ID])=[forms]![H-Cell test 1]![Product ID]));
There ya go..
Craig_Pettit
Try copying and pasting this in SQL view in a new query(so you don't lose your original one. It isn't much different but fingers crossed.)
SELECT TOP 1 [H-cell test].[associate ID], [H-cell test].[header type], [H-cell test].[header description], [H-cell test].productid, [H-cell test].[header size], *
FROM [H-cell test]
WHERE ((([H-cell test].productid)=[forms]![H-Cell test 1]![Product ID]));
Then make sure that the new query is the record source for your report.
To do this, open the report in design view, right click on the square in the top left hand corner, where the rulers meet, and click properties in the menu that should come up.
Go to the 'all' tab.
The first line, record source, select the new query that you have just created, or you can type it in.
When I run the query on my computer, a msgbox comes up asking for the value of forms!h-cell test 1!productid, which is what should happen if the form is not open.
If the form is open, it should use the value in that field to complete the query.
Good luck and let me know if you need any more help.
HTH
Craig.
Craig_Pettit
Sorry, just realised I've made a slight error.
I have put in productid as one word where it is two words in your sql, ie product id.
Sorry about that.
Pantherfan
everything works fine but it still opens and shows me the info from the 1st lable in the preview window when i print. The table updates to the last record as does the form, but the report always shows the 1st record. And for some reason, the data fields are blank. On the form, they have data in them. I dont understand why. There seems to be some info not being transfered from the table to the query.
Any thoughts on that?
Craig_Pettit
Do you have product Id on the form??
Are the form fields bound to the table?
If you look at the table are there several records in there or just 1?
Is product id an autonumber or a manually entered number?
Still got me stumped a bit but this info may help.
If anyone else has any ideas please feel free to jump in.
Craig.
Pantherfan
Do you have product Id on the form??
yes

Are the form fields bound to the table?
yes

If you look at the table are there several records in there or just 1?
there are 11 records when I look at the table

Is product id an autonumber or a manually entered number?
product ID is an autonumber..when the associate enters teir ID, the product ID generates an autonumber and a barcode

when I hit print, there are some docmds for the on click event that saves the current record, goto aclast and opens the print preview, and print.

Is there anything I should have in the even procedure for the report? On Open for example, that would make happen what i need to happen?

Edited by: Pantherfan on Tue Apr 5 3:24:39 EDT 2005.
Craig_Pettit
Good
Good
Good.
What does goto aclast do?? I don't know if you need this. If this takes you to the last record then this may be the problem.
Can you paste the code from the on_click event?
Try making a new button and use the wizard. Just tell it to open the report that you have created. If the query is the control source for the report then it should work.
Once you get this working, you can add the other bits to get it saving first etc.
If this doesn't work, are you able to attach the database in 97 format? You can do this under tools/database utilities/convert database.
Oknow we are going around in circles a bit but I'm just trying everything I can think of. I might have a better idea if its in front of me.
Craig.
Craig_Pettit
Found the problem!!!
omment out the goto aclast line.
It is going to the last record before it opens the report. Therefore, it will always open the last record, which for some reason is your first record, but I wouldn't worry about that.
In 97, docmd.goto ,, aclast is the code to go to the last record, so I'm only guessing.
You don't need this line to go to the one you've just put in because you are already showing the current record with the code on your query.
HTH
Craig.
Pantherfan
no problem..you're helping ALLOT
Ofound that i had some field named differently in the query and the table though..so im re-doing that. I think that happened in all the changing stuff I've been doing. That may solve the problem. ill let ya know..trying it now..
Craig_Pettit
I'm pretty sure its the goto aclast line.
See above.
Pantherfan
hmm..goto last line...will try that now
Craig_Pettit
Sorry, I meant that you need to comment out the line;
ocmd.goto aclast
This is making the form go to the last record before it runs the query, therefore when it runs the query it is showing you the last record every time which will be the one that you keep getting in your report.
It changes the product id to the product id of the last record, which is why your report is displaying this one.
If you take out that line of code or comment it out using a ' then it should work...
Good luck.
Craig.
Pantherfan
I took out the goto last line. But still the same.
How do I get the table to make the current record the active record, and the query to select that one?
The report shows the very 1st record i the form no matter whats highlighted in the table
Pantherfan
Ok..I finally got it. I created a new print button to take out the goto last record commands. The query thing is what fixed it. Thanks allot. Works perfectly now.
Thanks again!!
Craig_Pettit
No worries.
You don't have to tell it to go to the last record because the query is already telling it to display the record with the same product id as the product id on the form.
Glad we finally got there. Sorry it took so long, I'm usually the one asking for help rather than giving it.
Craig.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.