Skip to content
Advertisement

How to use VBA variable in SQL string? Enter Parameter Value error

I get a popup box asking for the parameter value for the value of CXIid

Enter Parameter Value
for CXI00012.

I tried ' " & CXIid & " ' but then I get a result of 0 rows being updated. However when I put a value in the where clause or into the Enter Parameter Value prompt I get the correct row updated.

How do I get it to recognize CXIid as a value?

Advertisement

Answer

You have a few different types of mistakes… the variables cannot be within the quotes, and since the field CXI_ID is a String, it does need quotes.

This assumes that the Consent field is numeric and the combobox is returning a numeric value as well.

Also note the spaces I added before SET and WHERE. Those are important.

Use MsgBox testSQL or Debug.Print testSQL to double check what testSQL is set to before you run it.

If the field CXI_ID is not a string but you are just using a string as the type of variable holding the value for some reason:

If they are both strings:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement