user1015214
user1015214

Reputation: 3091

Issue using VB in access to open up form with OpenForm

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

Answers (2)

iDevlop
iDevlop

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

PowerUser
PowerUser

Reputation: 11801

Try:

DoCmd.OpenForm("frm_add-remove", , , "ItemID = '" & var & "'", , , )

I did 2 things.

  1. Put frm_add-remove in quotes so it gets passed properly as a string and not as a variable name.
  2. Put var in quotes in case it is also a string.

Upvotes: 1

Related Questions