How to Print Just the one record I'm Viewing (1 Viewer)

Viper210

Registered User.
Local time
Today, 11:57
Joined
May 10, 2012
Messages
14
I found these procedures on how to create a command button to print just one record.

Followed them religously, but the button still prints all the records.

The steps

  1. Open your form in design view.
  2. Click the command button in the toolbox (Access 1 - 2003) or on the Controls group of the Design ribbon (Access 2007 and 2010), and click on your form.
  3. If the wizard starts, cancel it. It will not give you the flexibility you need.
  4. Right-click the new command button, and choose Properties. Access opens the Properties box.
  5. On the Other tab, set the Name to something like: cmdPrint
  6. On the Format tab, set the Caption to the text you wish to see on the button, or the Picture if you would prefer a printer or preview icon.
  7. On the Event tab, set the On Click property to: [Event Procedure]
  8. Click the Build button (...) beside this. Access opens the code window.
  9. Paste the code below into the procedure. Replace ID with the name of your primary key field, and MyReport with the name of your report.
My Code

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ClientID] = " & Me.[ClientID]
DoCmd.OpenReport "client 3", acViewPreview, strWhere

End If
End Sub

The second problem is that I created a second button, set up the properties identically to print a different Report "Intake 4".

All I changed was the DoCmd.OpenReport to "Intake4",
When I do this, it changes the original button to "Intake4" also.

How do I fix both problems?
 

Alansidman

AWF VIP
Local time
Today, 11:57
Joined
Jul 31, 2008
Messages
1,493
It changes the name on the button because you have given the command button the same name as the original button. In your properties for the second button, change the name from cmdPrint to something else. Perhaps, cmdPrint2

Alan
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 09:57
Joined
Aug 30, 2003
Messages
36,126
I think you have the wherecondition in the filter argument. Try

DoCmd.OpenReport "client 3", acViewPreview, , strWhere

This may help on syntax:

http://www.baldyweb.com/wherecondition.htm
 

Viper210

Registered User.
Local time
Today, 11:57
Joined
May 10, 2012
Messages
14
Thanks both of you for the reply's. First of all, I did change the name from CmdPrint to cmdPrint2 when I built the second button under the "Other" tab where it says "Name".

Is there something else in the command button properties that I need to change so access recognizes the two buttons as different buttons?

In reference to the "DoCmd.OpenReport "client 3", acViewPreview, , strWhere" filter argument, I have this under On Click under Event Procedure".

Is that in the correct place?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 09:57
Joined
Aug 30, 2003
Messages
36,126
That is the correct place. Does the updated code work to restrict the report now?
 

Viper210

Registered User.
Local time
Today, 11:57
Joined
May 10, 2012
Messages
14
pbaldy: Was your replied code a typo, you instructed me to put the same code in thats already there.
 

spikepl

Eledittingent Beliped
Local time
Today, 18:57
Joined
Nov 3, 2010
Messages
6,142
You have now presented two versions:

DoCmd.OpenReport "client 3", acViewPreview, strWhere (in #1)

and

DoCmd.OpenReport "client 3", acViewPreview, , strWhere (in #4)

The first one is wrong, the second one is right. Which one is in your code?

 

Viper210

Registered User.
Local time
Today, 11:57
Joined
May 10, 2012
Messages
14
Thanks for the reply, added the extra comma and was able to print single record.

Unfortunately, still can't get second button to work and now getting this error message when opening up the report "Client 3" listed in my code:

"Microsoft Access can't find the macro 'DoCmd'. The macro (or its macro group) is new but haven't been saved. Note that when you enter the macrogroupname.macroname syntax in an argument, you must specify the name the macros macro group was last saved under."

Any suggestions on how to build a 2nd button or how to get my report error message to go away?
 

Users who are viewing this thread

Top Bottom