Using variable in SQL string

LjushaMisha

Registered User.
Local time
Today, 10:44
Joined
Mar 10, 2017
Messages
81
Hello. I have a PEACE of code looking like that:

Dim ElKup1 As String
Dim sq As String



ElKup1 = (Forms!frmNotInList!Combo6.Column(1)) & " " & Forms!frmNotInList!Combo0.Column(1)

sq = "Update tblElements Set ElementName = ElKup1 WHERE ElementName=null;"

DoCmd.RunSQL sq

When I run the sub I (F5 or OnClick Event) get pop window asking me to input parameter's ElKup1 value.
What I'm doing wrong? Can Somebody help me?
 
since ElKup1 is string you must enclosed them with double aphostraphe in the expression.
also your construction of variable sq, is missing ampersand (&).
to compare variable to null, use Is Null or the function IsNull:

sq = "Update tblElements Set ElementName = " & Chr(34) & ElKup1 & Chr(34) & " Where ElementName Is Null;"

or

sq = "Update tblElements Set ElementName = " & Chr(34) & ElKup1 & Chr(34) & " Where IsNull(ElementName);"

DoCmd.RunSql sq
 
By the way what dies Misha means?
 
Hi Arnelgp.
GREAT THANKS
WORKED PERFECTLY FIRST TIME.

Just question: Why you used char(34) instead simply "

Best regards
 

Users who are viewing this thread

Back
Top Bottom