By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,616 Members | 1,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,616 IT Pros & Developers. It's quick & easy.

Print Current Record from Form

P: 6
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.
Jun 9 '09 #1
Share this Question
Share on Google+
11 Replies


Expert 100+
P: 1,287
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
Jun 9 '09 #2

P: 6
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
Jun 9 '09 #3

Expert 100+
P: 1,287
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.
Jun 9 '09 #4

P: 6
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
Jun 9 '09 #5

Expert 100+
P: 1,287
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
Jun 9 '09 #6

Expert 100+
P: 1,287
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.
Jun 9 '09 #7

P: 6
Printed all records now.

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

KC
Jun 9 '09 #8

P: 6
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
Jun 9 '09 #9

NeoPa
Expert Mod 15k+
P: 31,561
@KCwiz
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?
Jun 9 '09 #10

P: 6
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
Jun 10 '09 #11

NeoPa
Expert Mod 15k+
P: 31,561
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.
Jun 10 '09 #12

Post your reply

Sign in to post your reply or Sign up for a free account.