Solved Len Function

Weekleyba

Registered User.
Local time
Yesterday, 23:03
Joined
Oct 10, 2013
Messages
593
I have a form with some combo boxes and I want to verify they are filled prior to a command button executing some code.
One of the combo boxes has 43 options to select from and the combo box stores the ID as a number.
The issues is, when I select an option that has an ID 10 or greater, it will not move forward but executes the "Then" portion with the msgbox.
How do I fix this?
Code:
Private Sub AutoGenerate_DblClick(Cancel As Integer)
    If (Len(Me.cboProjectFY & vbNullString) And Len(Me.cboLocation & vbNullString) And Len(Me.cboProjectType & vbNullString) And _
    Len(Me.cboFacilityType & vbNullString) And Len(Me.cboFundingType & vbNullString)) = 0 Then
    
    MsgBox "Fill out Bergen Number details prior to clicking."
    
    Else
    Call fncUpdateBerger
    End If

End Sub
 
The logic of your IF statement's criterion is incorrect.

Reducing each LEN() function to an arbitrary variable, what you asked was IF X AND Y AND Z .... = 0 THEN... ELSE ... END IF

I am thinking that what what you really want is different than that. The way that the AND operator works, if ANY of things is of length zero then you will get a 0. In that context, what you have is a bitwise AND operating on integers (because LEN returns an INTEGER).

Perhaps you REALLY wanted this: IF X = 0 AND Y = 0 AND Z = 0 ... THEN ... ELSE ... END IF

This would be more in line with what the AND operator normally does. You get a truth value for each part, then apply the AND operators.

But my second question is the use of AND in this context. Do you really mean "AND" in this case? Is it your desire to have your message if ANY of those are empty? If so, the AND might not be appropriate anyway. Please state your actual English requirements, not the code that doesn't do what you want. Tell us what you REALLY want.
 
Thanks Doc Man.
You are correct, I really wanted IF X = 0 AND Y = 0 AND Z = 0 ... THEN ... ELSE ... END IF.
I'll try to be more clear next time.
Sure appreciate the help!
 

Users who are viewing this thread

Back
Top Bottom