Printing a record from a form ?

Muzicmn

Registered User.
Local time
Today, 15:54
Joined
Nov 3, 2002
Messages
78
I have seen several threads on this but for some reason i cannot get it to work.

pblm: i have a form, pretty basic actually, empid, OTdate, hoursassigned

when Overtime for the employee is assigned thru this form i would like the program to print a letter to the employee notifiying them of such.

So, i created a report in the format i want the letter to read (referencing all the appropriate fields from the table used by the form) but i am not sure on how to make the report print for the current entry in the form

thanks ahead of time

Ricky
 
Macro

Bit of a novice myself! Try this in the Where Condition as advised by Gumby in a previous thread I posted:

Check the Macro for criteria. On the bottom of the screen in the Action Arguments there is a Where Condition argument. You might not have it set correctly to pull the data from the form.

[Field Name From Form you are Opening] = [Forms]![Form Your Field value Lives On]![Field Name on Form Where Value is Coming From]
Hope this helps.
Phil.
 
Try This :

Code:
Dim strDocName as string
Dim strLinkCriteria as string

strDocname = "YourReportName"
strLinkCriteria = "[PrimaryKeyField] = Forms![Formname]![PrimaryKeyField]"
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70  ' Saves record before display in Report
Docmd.openreport strDocname,acviewpreview, strLinkCriteria , "[PrimaryKeyField] = Forms![Formname]![PrimaryKeyField]"

I have similair code in one of my db's

Hope this helps

Andy
 
Last edited:
Do MenuItem is obsolete now, use RunCommand acCmdSaveRecord instead
 
Of course you right Rich.

Just taken the code from an old db, didn't look at properly.

;)
Andy
 
hey guys,

i am kinda a newbie to this, where do i enter that code????
 
You can add it on the Onclick event of a command button on your form.

Create a command button then select properties> Event Tab

Then select ONCLICK . And add your code in VBA.

Andy
 
works like a champ, but still have a small problem, could be in the way i structered the db....

what i am actually using is 2 tables....one stores the employees name, working initials, phone #'s etc... the other stores overtime activites....date assigned, amount of hours, supervisor who assigned it, and it pulls the operating initials from table one to reference the employee.

now, when i run the code, i used the operating initials as the primary key field and it shows me ALL records that match those initials....including previously assigned ot. i think i need to add a second filter to also find the date that is displayed on the form. not sure how to add the second criteria or in what order it should go in...

once again thanks alot of all your help

Ricky
 
Last edited:
Ricky,

Is the date field recorded to the table? If so then just add the field to the report and it will display your required data from the form onto the report. As the code grabs the current record, based on the PK.

Have you assigned the code properly has it should only grab the current record in the form and NOT all records that are like a particular field?

If not do us a favour and post a db with the forms/reports/tables that we are talking about so I can have a look.

Andy
 
Last edited:
will trim the db and post later this evening as i do not have the ability to do that here at work, but in the meantime

what is happening with the code is that it is grabbing the initials from the form and apparently doing a search in the db for all records that match the initials.....the code i entered is as follows:


Dim strDocName as string
Dim strLinkCriteria as string

strDocName = "report1"
strLinkCriteria = "op_initials = Forms!OT_Events!op_initials"
DoCmd.RunCommand acCmdSaveRecord
DoCmd.openreport strDocName, acviewpreview, strLinkCriteria , "op_initials = Forms!OT_Events!op_initials"


do you think i am missing something???

Ricky
 
Enclose the criteria in [].

As follows:

Code:
Dim strDocName as string
Dim strLinkCriteria as string

strDocName = "report1"
strLinkCriteria = "[op_initials] = Forms![OT_Events]![op_initials]"
DoCmd.RunCommand acCmdSaveRecord
DoCmd.openreport strDocName, acviewpreview, strLinkCriteria , "[op_initials] = Forms![OT_Events]![op_initials]"

If it still does it then as a test do the following:

Open the form and save the record by clicking on the tab on the left hand side of the form then press the cmd button. If this works then runcommand line is not working properly.

Let me know how you get on.

Andy
 
Ricky,

Code:
Dim strDocName as string
Dim strLinkCriteria as string

strDocName = "report1"
strLinkCriteria = "[op_initials] = '" & Forms![OT_Events]![op_initials] & "'"
DoCmd.RunCommand acCmdSaveRecord
DoCmd.openreport strDocName, acviewpreview,, strLinkCriteria

Wayne
 
Dont know why the code isnt working, it still brings up all records with those initials instead of the one in the form

now for the good news....

i managed to get it to work by creating another field, autonumber field, this way making each record unique....and used this field under the code......works great

thanks for all the effort guys

Ricky
 

Users who are viewing this thread

Back
Top Bottom