user3038522
user3038522

Reputation: 21

Trouble using variables in VBA SQL WHERE Clause

I am trying to update a table using variables in VBA for Access. The statement is below.

DB.Execute "UPDATE tblSearchersList SET '" & vSearcherDay & "' = " & VHours & " 
WHERE Member= '" & Me.cboMember.Column(1) & "'AND [Mission] = '" & Me.Mission & "'"

tblSearcherList is table to update

vSearcherDay is a variable that combines the letter "d" with a number, et(1,2,3,4,5) depending on other query

VHours is a decimal number (number of hours)

Member is a text value from Form Field Me.cboMember.Column(1)

Mission is a text value from form field Me.Mission

I get Runtime error 3061 - Too few parameters expected 2.

Hope I can get some help with this as I have been fighting it for awhile and am losing the battle.

Thanks

New code is this:

Sorry bout the comments thing. I am new and didn't quite know how to do this.

DB.Execute "UPDATE tblSearchersList SET " & vSearcherDay &_
" = " & VHours & " WHERE Member= '" & Me.cboMember.Column(1) & "' &_
" And [Mission] = '" & Me.Mission & "'"

I am quite embarrassed about this but I had the Member field name wrong. Should've been MemberName instead. I really do appreciate all the quick help I got and will do better next time. It works perfectly. Thank you all.

Upvotes: 2

Views: 3620

Answers (1)

Yuriy Galanter
Yuriy Galanter

Reputation: 39777

Don't use apostrophes around field name. Instead

SET '" & vSearcherDay & "' = " &

do

SET " & vSearcherDay & " = " &

Upvotes: 1

Related Questions