Link to home
Start Free TrialLog in
Avatar of gbnorton
gbnortonFlag for United States of America

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
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

case sensitive issue?
strMySQL  <> strMySsql....
please check/confirm, also by using OPTION EXPLICIT to ensure you declare all your variables.
Avatar of gbnorton

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.
This code is illogical to me but works:
    If IsNull(Me.txtPCBoard_Lot_No1) Then
        strDoNothing = "Doing Nothing"
    Else
        strMySQL = strMySQL & "[PCBoard_Lot_No1] = " & str_txtPCBoard_Lot_No1
    End If

    If IsNull(Me.txtPCBoard_Lot_No2) Then
        strDoNothing = "Doing Nothing"
    Else
        strMySQL = strMySQL & [PCBoard_Lot_No2] = " & str_txtPCBoard_Lot_No2"
    End If
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
do you have something a variable or string with the & directly attached, aka with no space?

"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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'll update you tomorrow.  Out today.  Thanks, Brooks
thank you,
Brooks