Expected: expression

leighj

Registered User.
Local time
Today, 19:30
Joined
Apr 5, 2017
Messages
10
Hi All... I'm sure this is something very basic and simple - but I can't get it.

This line keeps shouting an 'Expected: expression' compile error at me -

Code:
DoCmd.OpenReport tblEquipment, acViewNormal, , txtBarcode= & txtBarcode

Can anyone please advise?

Full Code:
Code:
Private Sub Command26_Click()

Dim x As Integer
x = MsgBox("Item succesfully loaned. Do you want to print a booking sheet?", vbYesNo)
If x = vbNo Then
x = MsgBox("no", vbOKOnly)
Else
x = DoCmd.OpenReport tblEquipment, acViewNormal, , txtBarcode= & txtBarcode
End If
 
End Sub
 
The last argument needs to be a string. You have not provided that.
 
On it's own line, it works fine:

Code:
DoCmd.OpenReport "tblEquipment", acViewNormal, , "txtBarcode=" & txtBarcode

but as soon as I put it into the line in my code for it to fire on vbYes - it doesn't.

Sorry, very much a novice!
 
On it's own line, it works fine:

Code:
DoCmd.OpenReport "tblEquipment", acViewNormal, , "txtBarcode=" & txtBarcode
but as soon as I put it into the line in my code for it to fire on vbYes - it doesn't.

And in your code:

x = DoCmd.OpenReport tblEquipment, acViewNormal, , txtBarcode= & txtBarcode
If you look, there are at least three issues:

  • First off, you don't need to set x = DoCmd.OpenReport. Just strip off the whole "x = " and leave it at DoCmd.OpenReport plus the parameters.
  • The second is tied to the first: if you set a variable equal to a function, then the function's parameters MUST be enclosed in parentheses. If you follow my advice for the first part, though, then don't worry about the parentheses, because you won't be returning a value.
  • Third, note the difference in the WHERE clause between your standalone line and your line in the code. Those quotes are necessary.
 

Users who are viewing this thread

Back
Top Bottom