AlexaS

Board Regular
Joined
Oct 12, 2012
Messages
158
Ok, I've been trying to figure this out for a few days and it just isn't working no matter what permutations I put it through. What I'm trying to do is open a report based on the record in the form (and only that one so that I can save it to a PDF individually instead of in one big congolmerate report). I created a button and put this code in the expression builder for the On Click event:

Code:
= DoCmd.OpenReport "LossDamageRPT", acViewPreview,,"[CLAIMNUM] ='" & [CLAIMNUM] & "'"


The error that I keep receiving (no matter how I adjust this) is: The expression you entered contains invalid syntax. You may have entered an operand without an operator. It gives me this error even when I take it down to just the report title. I cannot figure out (from searching online or in my books) how to adjust this.

I've tried making this just a simple Open Report button (by adding parenthesis around the report title) but that (when clicked) causes an error that Access failed to evaluate one or more expressions because "DoCmd" was referenced in an expression.

I need to get this figured out. Any help (as always) is gratefully received and fully appreciated.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
"[CLAIMNUM] ='" & [CLAIMNUM] & "'"

i haven't used access for ages

would "[CLAIMNUM] ='" & 5643 & "'" (OR something) work, i can't get past the feeling that the selection is the same as the value you want
 
Upvote 0
That's one of the permutations I've tried with having "[CLAIMNUM] ='" & Forms!DEClaims![CLAIMNUM]

I need the report to open to the claim number that matches the claim number on the form, I just don't know how to get it to do that.
 
Upvote 0
Why is there an equals sign at the start of this? That doesn't look right. Do you have the actual (complete) procedure for this event? Should be something like:

Code:
Private Sub MyButton_OnClick()
     DoCmd.OpenReport "LossDamageRPT", acViewPreview,,"[CLAIMNUM] ='" & [CLAIMNUM] & "'"
End Sub


Note that because you are using quotes it is assumed that ClaimNum is a TEXT field in the databse.
 
Upvote 0
I'm using the expression builder, it automatically adds the equals sign. Should this be under the macro builder instead?

ClaimNum is a text field in the database.
 
Last edited:
Upvote 0
Ok, I switched it to the code builder.

Code:
Private Sub Command433_Click()
    DoCmd.OpenReport "LossDamageRPT", acViewPreview, , "[CLAIMNUM] ='" & Forms![DEClaims]![CLAIMNUM] & "'"
End Sub

This works correctly and opens the report for just that record. Thanks for pointing out what should have been obvious! :LOL:
 
Upvote 0
Okay. I'm not very familiar with the expression builder. I think one other option is to write the sub first, then put the name of the sub in the on click event's property field. But what you see above is what I do about 99% of the time. There's probably a way that what you were doing was supposed to work but I personally don't have experience with that method.
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,794
Members
449,048
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top