Reputation: 3091
I have a Inventory form. I want to create an Update button which, when clicked, will open up a new form frm_add-remove, which will contain only the selected inventory item and will allow you to edit the stock quantity. I have listed the click event below, and it doesn't work:
Private Sub A_Click()
Dim var As Variant
var = Forms![frm_Inventory]![ItemID]
DoCmd.OpenForm(frm_add-remove, , , "ItemID = " & var, , , )
End Sub
and got a compilation error, Expected: expression. ItemID is a column in the frm_Inventory table, as well as in the frm_add-remove table.
I tried with and without the trailing commas. Do I have a syntax error? I thought that you can concatenate with either + or &?
Upvotes: 0
Views: 536
Reputation: 25272
Form name must be a string. Add the missing quotes around it.
DoCmd.OpenForm("frm_add-remove", , , "ItemID = " & var )
And anything AFTER the last non empty argument is unnecessary (and therefore to remove :)
Upvotes: 0
Reputation: 11801
Try:
DoCmd.OpenForm("frm_add-remove", , , "ItemID = '" & var & "'", , , )
I did 2 things.
frm_add-remove
in quotes so it gets passed properly as a string and not as a variable name.var
in quotes in case it is also a string.Upvotes: 1