PRINT CURRENT RECORD from Form (1 Viewer)

jenny23

Registered User.
Local time
Yesterday, 18:30
Joined
Apr 1, 2004
Messages
47
Hello friends,
Can any 1 please show me how to print a current record from form? I tried to create a Print button, but when I click on it, it just print all the records.
Please help.
Jenny.
 

doran_doran

Registered User.
Local time
Yesterday, 20:30
Joined
Aug 15, 2002
Messages
349
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click


DoCmd.PrintOut

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

End Sub



I think you have to make some adjustment on your form properties.

I can send you the print screen of my form perperties.

Good Luck.

Dianna Goldsberg
 

Attachments

  • InvSP32-20040518-123958.gif
    InvSP32-20040518-123958.gif
    12.9 KB · Views: 4,896
  • InvSP32-20040518-124002.gif
    InvSP32-20040518-124002.gif
    11.3 KB · Views: 3,511
M

Mike375

Guest
jenny23 said:
Hello friends,
Can any 1 please show me how to print a current record from form? I tried to create a Print button, but when I click on it, it just print all the records.
Please help.
Jenny.

You can make a macro (or code) to open a form that isa copy of your form to match the record that is open and then put Printout in the macro and then a Close the form action.

That way only one record is involved.

Mike
 

doran_doran

Registered User.
Local time
Yesterday, 20:30
Joined
Aug 15, 2002
Messages
349
Dont Ever Do Macro....

Dont ever do Macro. I just finished converting All the old macro from an ex employee to VB. Trust me it's better in VB. Never do Macro.
 

jenny23

Registered User.
Local time
Yesterday, 18:30
Joined
Apr 1, 2004
Messages
47
Hello,
It doesn't work.
It still prints all records.
Please help.
Jenny.
 

doran_doran

Registered User.
Local time
Yesterday, 20:30
Joined
Aug 15, 2002
Messages
349
hmm

Did u change the properties of the form according to the picture files attached in my last response.
 
M

Mike375

Guest
doran_doran said:
Dont ever do Macro. I just finished converting All the old macro from an ex employee to VB. Trust me it's better in VB. Never do Macro.

What are the negatives.
 

jenny23

Registered User.
Local time
Yesterday, 18:30
Joined
Apr 1, 2004
Messages
47
I changed the Cycle to Current Record
I changed the Control box to No.
I created a Print button on the form, and paste your code at the On Click.

That's all I did.

Help.

Jen.
 

doran_doran

Registered User.
Local time
Yesterday, 20:30
Joined
Aug 15, 2002
Messages
349
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click


Dim strFilter As String
strFilter = "OrderID = Forms!Orders!OrderID"

DoCmd.PrintOut

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

End Sub



==================================================

Change the orderid to real id (or whatever id you have, can be autonumber too), change orders to whatever your form name and the orderid field to ur id.

Good luck
 

jenny23

Registered User.
Local time
Yesterday, 18:30
Joined
Apr 1, 2004
Messages
47
It still prints all records.
I really don't know why.
It is supposed to be easy.
Please help.
thanks.
Jenny.
 
M

Mike375

Guest
jenny23 said:
It still prints all records.
I really don't know why.
It is supposed to be easy.
Please help.
thanks.
Jenny.

Jenny

Did you try the idea of opening a form filtered to match the record on your main form. That will only have the once record to print.

If want a 10000% solution then:

Make a query based on the same table or query as your main form and have for criteria reference to the ID on your main form. Put in the criteria
[Forms]![MyMainForm]![ID or whatever]

Make a copy of your main form and for its data source use the above query.

Then with your code open that form, print and then close the form. There is no way that will print more than one record.

Mike
 

jenny23

Registered User.
Local time
Yesterday, 18:30
Joined
Apr 1, 2004
Messages
47
I am really a newbie in ms access, can you please show me in detailed how to do this?
Thanks very much.
Jenny.
 
M

Mike375

Guest
jenny23 said:
I am really a newbie in ms access, can you please show me in detailed how to do this?
Thanks very much.
Jenny.

OK,

The first thing to do is make a copy of your form. In the data base window just click on the form name with the right clicker and a menu will come up. Then with left clicker click on copy. Then anywhere in the blank space right click and this time the menu will come up with paste.

Alternatively, click and highlight the form name and go up to file and SaveasExport. You should get an option to either save in an external data base or within the data base. Pick the one with Witin the Current Data base and it will save your form with a name like Copy of your FormName.

Then let me know when you have a copy of your form made and we can take it one stage at a time. We are going to use the copy of your form for the printout. We could use your actual form but there are pluses in using the second form.

Mike
 

biskra

Registered User.
Local time
Today, 02:30
Joined
Jan 12, 2004
Messages
35
try this

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "REPORTNAME", , , "[ID]='" & forms![Forname]![TXTBOXNAME] & "'"
DoCmd.SetWarnings False
DoCmd.PrintOut acPages, , , , 1
DoCmd.Close acReport, "REPORTNAME"
DoCmd.SetWarnings True
 

jenny23

Registered User.
Local time
Yesterday, 18:30
Joined
Apr 1, 2004
Messages
47
Hello Mike,
I have done that.
What 's next?

Thanks.
 

doran_doran

Registered User.
Local time
Yesterday, 20:30
Joined
Aug 15, 2002
Messages
349
Post your database...

Jenny,

Why dont you zip your database and post it here. It's easier to work from a database instead throwing advice back and forth. Since, you are new to Access there are many term that will go over your head.

Dianna goldsberg
 

jenny23

Registered User.
Local time
Yesterday, 18:30
Joined
Apr 1, 2004
Messages
47
I tried your code. I put a Print command button on the form called Print, then I open this button properties and paste the code on the On Click event, but it showed this error:
Run-time error "438"
Object doesn't support this property or method
and, it highlighted this line:

DoCmd.OpenReport "rptA", , , "[ID_Num]='" & Forms![frmTR]![cmdPrint] & "'"

Please help.

Rich said:
Why the PrintOut etc.etc. Why not just OpenReport, acNormal ?
 

jenny23

Registered User.
Local time
Yesterday, 18:30
Joined
Apr 1, 2004
Messages
47
my db

This is my DB. When open it, click on the form, you 'll see what I am talking about.
Please help, guys.
Thanks.
Jenny.
 

Attachments

  • testingPrintDB.zip
    33.3 KB · Views: 399
M

Mike375

Guest
jenny23 said:
Hello Mike,
I have done that.
What 's next?

Thanks.

Jenny,

Ok then!! I will assume you have not made a macro before......we are about to make a real simple one, but a couple of things first up.

In this exercise I will call your form that you wsant to print from MainForm and the copy you made PForm. You just insert the actual names.

Now for this to work you need to have an entry in each record that is unique to that record, such as an autonumber field or some other field that has unique information. For example, Surname would be no good because you might have (or will end up having) more than one person with the same surname.

Anyway, whatever the field is that has a unique value for each record I will call [NameNumber] and you just insert your actual field name.

So we have MainForm for the frm from which you want to print.
We have PForm for the copy you made.
We have NameNumber representing your unique field.

Making a macro looks a bit like making a table and you go to New macro and the macro design screen will open. Note: Your version of Access might be a bit different to what I use. So if you have trouble then post this part up on the Macro forum and someone will quickly translate to your version but I think we will be Ok anyway for the type of simple macro we are about to make.

When the screen opens on new macro in design view you will see that it looks a bit like a table in design view.

There are two colums Conditions and Action. Conditions probably won't be displaying but if you clicked on View on the toolbar and then clicked Conditions it will appear. However, we won't need Conditions for this macro.

The first thing to do is click on the first line of the Action column and a drop down list arrow will appear. From this list find OpenForm and click on it.

When you do that OpenForm will appear on the action line and set of boxes will appear at the bottom of the screen and they should look something like this

Form Name
View
Filter Name
Where Condition
Data Mode
Window Mode

View will have defaulted to Form, Data Mode should have defauted to Edit and Window Mode should have defaulted to Normal.

Now for form name enter the name of the form which you made as a copy.

The only other one you need to worry about is Where condition and in that box enter.

[NameNumber]=[Forms]!MainForm]![NameNumber]

Remember you enter the name of the form you will launch Print from in place of where I have MainForm and enter the field name of your unique field where I have NameNumber.

Now you save this macro just as you would a form or table and it might default to a name like Macro1.

Now at this stage we have not included Print as we want to make sure your macro is opening the seconds form you made on a record that matches your main form.

Two things to do now to test.

Go to your MainForm in Design View and attach the Macro to an OnClick event. That might be a command button or you might make a label from the tool box. Note: Label that appear on the form as a result of you dragging fields to the form from the field list do not have the facility for the various events. If you have any trouble in this area with making a label or command button then just attach (for now) the macro to OnClick event for one of the textboxes you have.

One you attached the macro I want you to go to the copy of the form you made and in Design View. In Design view change a few colours so that when the macro opens the form you will instantly see that it is a different form that has opened.

If we have success on this section then the rest is real easy.

When you run the macro the form should open with the matching record and say at the navigation buttons 1 of 1 filtered.

Then click the print icon.

If all is well, then we go back and add a couple of lines to the macro. One will be for the Printing and the other will close form.

It is nealry midnight here in Sydney Australia so if I miss you I will check in the morning as I will go to bed in an hour or so.

Good luck

Mike
 

Users who are viewing this thread

Top Bottom