gbnorton
asked on
vba if statement returns false
I'm using the if statement below to modify the string strMySql.
' initialize
strMySQL = "Update Part_Serial_Number Set "
'build sql statement from text boxes that have data
If Me.txtPCBoard_Lot_No1 <> "" Then
strMySQL = strMySQL & "[PCBoard_Lot_No1] = " & str_txtPCBoard_Lot_No1
End If
DoCmd.RunSQL strMySql
When Me.txtPCBoard_Lot_No1 is empty, strMySql is being set to "False". I would expect it to just leave strMySql as it was.
I don't recall seeing this before. Any ideas?
Thanks,
Brooks
' initialize
strMySQL = "Update Part_Serial_Number Set "
'build sql statement from text boxes that have data
If Me.txtPCBoard_Lot_No1 <> "" Then
strMySQL = strMySQL & "[PCBoard_Lot_No1] = " & str_txtPCBoard_Lot_No1
End If
DoCmd.RunSQL strMySql
When Me.txtPCBoard_Lot_No1 is empty, strMySql is being set to "False". I would expect it to just leave strMySql as it was.
I don't recall seeing this before. Any ideas?
Thanks,
Brooks
ASKER
In the code I posted I see I used both upper and lower case. In the project code I verified the variable name is correct and consistant. Option Explicit set.
ASKER
This code is illogical to me but works:
If IsNull(Me.txtPCBoard_Lot_N o1) Then
strDoNothing = "Doing Nothing"
Else
strMySQL = strMySQL & "[PCBoard_Lot_No1] = " & str_txtPCBoard_Lot_No1
End If
If IsNull(Me.txtPCBoard_Lot_N o2) Then
strDoNothing = "Doing Nothing"
Else
strMySQL = strMySQL & [PCBoard_Lot_No2] = " & str_txtPCBoard_Lot_No2"
End If
If IsNull(Me.txtPCBoard_Lot_N
strDoNothing = "Doing Nothing"
Else
strMySQL = strMySQL & "[PCBoard_Lot_No1] = " & str_txtPCBoard_Lot_No1
End If
If IsNull(Me.txtPCBoard_Lot_N
strDoNothing = "Doing Nothing"
Else
strMySQL = strMySQL & [PCBoard_Lot_No2] = " & str_txtPCBoard_Lot_No2"
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
do you have something a variable or string with the & directly attached, aka with no space?
"string"& vs "string" &
or
variable& vs variable &
"string"& vs "string" &
or
variable& vs variable &
If Nz(Me.txtPCBoard_Lot_No1, "") <> "" Then
strMySQL = strMySQL & "[PCBoard_Lot_No1] = " & str_txtPCBoard_Lot_No1
End If
strMySQL = strMySQL & "[PCBoard_Lot_No1] = " & str_txtPCBoard_Lot_No1
End If
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'll update you tomorrow. Out today. Thanks, Brooks
ASKER
thank you,
Brooks
Brooks
strMySQL <> strMySsql....
please check/confirm, also by using OPTION EXPLICIT to ensure you declare all your variables.