Connecting Tech Pros Worldwide Help | Site Map

Print Current Record from Form

Newbie
 
Join Date: Jun 2009
Posts: 6
#1: Jun 9 '09
I am relatively new at this stuff, but I have managed to create two awesome databases for a law office. I am finishing up with a "print report from current record" command button. I have worked my way to this..
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport"File Request", acViewNormal,,"[ID] = "&Me![CLIENT]
ID is a number. This gets me where I want to be but I get a syntax error "operator missing" @ 'ID=client'. I have tried rearranging and other syntax. I have seen it done a couple of ways, but the above actually gets me to the current client data.

I need help. I am going crazy.
Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,160
#2: Jun 9 '09

re: Print Current Record from Form


For debugging, try this.
Expand|Select|Wrap|Line Numbers
  1. Dim strWhere as String
  2. strWhere = "[ID] = " & Me.Client
  3. MsgBox strWhere   'or breakpoint for Debug
  4. DoCmd.OpenReport "File Request", acViewNormal, , strWhere
Newbie
 
Join Date: Jun 2009
Posts: 6
#3: Jun 9 '09

re: Print Current Record from Form


Didn't work, gave me message box "ID = Jan Smith" Ok? So I clicked ok and it returned the same error message "Syntax Error (missing operator) 'ID = Jan Smith'

If I try it a different way (I have tried so many) "on click" it asks for ID--Parameter Value

HELP, this is the last part of my db and I am done.

Kim
Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,160
#4: Jun 9 '09

re: Print Current Record from Form


Yes, it worked perfectly, but your logic is wrong. I thought you said that ID was a number. Clearly you want something other than [Client] from your form.
Newbie
 
Join Date: Jun 2009
Posts: 6
#5: Jun 9 '09

re: Print Current Record from Form


The ID is a number "long integer". Here's what I am doing. I want a command button on my form that will print a report of the current record based on a query I created for the report that contains the fields, CLIENT, ADDRESS, REP, TYPE. So after much googling I found
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "ReportName", acViewNormal,,"[ID] = & Me![ID]
When I use this one, it returns the "Enter Parameter Value".

Thank you so much for your quick responses!!!!

KC
Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,160
#6: Jun 9 '09

re: Print Current Record from Form


So your report does not have the [ID] field? Maybe you need:
Expand|Select|Wrap|Line Numbers
  1. Dim strWhere as String 
  2. strWhere = "[Client] = '" & Me.Client & "'"
  3. 'MsgBox strWhere   'or breakpoint for Debug 
  4. DoCmd.OpenReport "File Request", acViewNormal, , strWhere
Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,160
#7: Jun 9 '09

re: Print Current Record from Form


Consider any code you find as example only. You will very rarely be able to copy and use code without changing field names such as [ID] to the proper names that you have chosen. In this case, ID should be replaced with the name of the field you use as the primary key, which IDentifies the record.
Newbie
 
Join Date: Jun 2009
Posts: 6
#8: Jun 9 '09

re: Print Current Record from Form


Printed all records now.

Thanks for your help! What am I missing. It usually doesn't take me this long to "get it".

KC
Newbie
 
Join Date: Jun 2009
Posts: 6
#9: Jun 9 '09

re: Print Current Record from Form


I realize about the copying code. I use it to point me in the right direction. I do have an ID field (autonumber). That is why I left it in I changed it originally to ....."[ID] = "&Me! [CLIENT]
and that got me to where it was actually picking up the current record, but also giving me the syntax error (missing operator).

thanks.

KC
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,686
#10: Jun 9 '09

re: Print Current Record from Form


Quote:

Originally Posted by KCwiz View Post

Thanks for your help! What am I missing. It usually doesn't take me this long to "get it".

It's hard to know Kim.

Lookups (where you have a number associated with a string and you use that number to represent the string) are often a source of confusion.

Filtering on the [ID] value, generally requires a number. Often these numbers are hidden behind a ComboBox control where only the string value is visible. In such cases the number is generally used by the program, and needs to be passed into the SQL for the filter.

Does this make sense?
Newbie
 
Join Date: Jun 2009
Posts: 6
#11: Jun 10 '09

re: Print Current Record from Form


LET ME THANK YOU GUYS FOR YOUR HELP!!! I came in this a.m. and started playing around with it and this is what worked. I could swear I used this before.
Expand|Select|Wrap|Line Numbers
  1. Private Sub
  2. Dim strWhere As String
  3. DoCmd.OpenReport"REPORT", acViewNormal,,"[CLIENT] = ' " & Me.CLIENT & " ' "
  4.  
  5. End Sub
AGAIN, thanks for your help!!!!

KC
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,686
#12: Jun 10 '09

re: Print Current Record from Form


Hi Kim. Welcome to Bytes!

Let me just add some clarification here, for other readers benefits.

This code is not copy/pasted in and should not be expected to work as is. The spaces around the single-quotes will mean that no real data is ever matched. The actual code used is not exactly as posted here. This is almost certainly due to copying the data inaccurately. It probably works fine in real-life.

As a last point, I should mention that the CODE tags must be used when posting. This is not optional. As a new member I'm sure you're just getting to grips with things so I'll include some helpful pointers on this.

Tags are done as matching pairs where the opening one is surrounded by [...] and the closing one by [/...]. A set of buttons is available for ease of use in the Standard Editor (Not the Basic Editor). The one for the [ CODE ] tags has a hash (#) on it. You can choose which editor to use in your profile options (Look near the bottom of the page).

Very last point, as I'm posting anyway, Line #2 is redundant.
Reply