• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

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
0
gbnorton
Asked:
gbnorton
2 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
case sensitive issue?
strMySQL  <> strMySsql....
please check/confirm, also by using OPTION EXPLICIT to ensure you declare all your variables.
0
 
gbnortonAuthor Commented:
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.
0
 
gbnortonAuthor Commented:
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
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Jeffrey CoachmanMIS LiasonCommented:
1. Is what you posted originally the *entire* code...?
I don't see where you are declaring: strMySQL

2. To be sure, I always check for null as well as an empty string:
If Me.txtPCBoard_Lot_No1 <> "" Or not isnull(Me.txtPCBoard_Lot_No1) Then
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
do you have something a variable or string with the & directly attached, aka with no space?

"string"&  vs "string" &
or
variable& vs variable &
0
 
hnasrCommented:
If Nz(Me.txtPCBoard_Lot_No1, "")  <> "" Then
        strMySQL = strMySQL & "[PCBoard_Lot_No1] = " & str_txtPCBoard_Lot_No1
End If
0
 
Walter RitzelSenior Software EngineerCommented:
The code you posted is very logical, and you should do what boag2000 mentioned... Test the variable for NULL and <> "" to make sure you caught all the situations where you dont want to issue your update.
0
 
gbnortonAuthor Commented:
I'll update you tomorrow.  Out today.  Thanks, Brooks
0
 
gbnortonAuthor Commented:
thank you,
Brooks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now