Need some simple VBA to print a form

nicktheblue

Registered User.
Local time
Today, 09:48
Joined
Sep 15, 2001
Messages
18
Hello all,
A quick question which is probably beneath most people on the forum...
I have created a command button on a form, which I would like to print the specific form on which the button is clicked, not every record in the database! I would like a command which therefore filters that record by its OrderID and then executes the DoCmd - Print (or whatever the damn magic spell is!). Also, if I wished to print a report which is based on said OrderID, can this be done in , say, less than 3 pages of code, or should I enroll myself on a "VB for brainless morons" course? I believe they may run these at my local college.
Thanks in advance,

Nick
 
There are several ways to accomplish this - this simple way doesn't require much code at all.

This procedure assumes that you arrived at the current record by way of a ComboBox. If not, just reply with the method used and I will try to help.

Place a ComboBox on the Form, choose 'Find a record on my form based on...etc.' and include OrderID as the bound column. Name this object Combo1.
Whatever you choose in the ComboBox is now the current record, based on the OrderID. The code behind it will be similar to this:
Me.RecordsetClone.FindFirst "[OrderID] = '" & Me![Combo1] & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark

In the On Click event for your Command Button, type this code:

Dim stDocName As String
stDocName = "rptMyReport" 'the name of your report goes between the double quotes
DoCmd.OpenReport stDocName, acNormal, , "[OrderID] = '" & Me.Combo1 & "'"

This will print the report based on the OrderID chosen in your ComboBox.

Note: The query or SQL statement that your report is based upon must also contain the OrderID field.

If this doesn't do it for you or if you need more help just reply here.

Shep
 
Thanks Shep -
I could do with using the 'OnLoad' event on the form itself to set the order ID as there are a number of different ways to arrive at the form I wish to print. Is this possible?

Any help / advice is always much appreciated,

Thanks again,
Nick.

[This message has been edited by nicktheblue (edited 10-16-2001).]
 

Users who are viewing this thread

Back
Top Bottom