if then else

Thedon123

Registered User.
Local time
Today, 15:46
Joined
Sep 11, 2002
Messages
98
I have a problem. a user selects a values in an cascading combo.
when he reaches the last one he clicks on select. this gives him an msg box telling the code of the last combo.

what i am trying to do is to give him an error if there is nothing in the last combo. i.e it is blank which means the msgbox cannot display any code.

i have used the code below. the problem is that the code doesnt recognise the "" as a null value, so how do make it recognise a null value.


Private Sub SelectSRO_Click()

If Me!SearchOperations.Value = "" Then
MsgBox "There is no value"
Else
MsgBox "Please enter or select " + "'" + Me!SearchOperations.Value
End If
DoCmd.Close acForm, "SRO_Search_Add"



End Sub
 
If IsNull Me!SearchOperations Then
MsgBox "There is no value"
Else
MsgBox "Please enter or select " + "'" + Me!SearchOperations.Value
End If
DoCmd.Close acForm, "SRO_Search_Add"
 
try using .text = "" instead of .value = ""

Hope this helps!
 
Private Sub SelectSRO_Click()

If Me!SearchOperations.Value = vbNullString Then
MsgBox "There is no value"
Else
MsgBox "Please enter or select " + "'" + Me!SearchOperations.Value
End If
DoCmd.Close acForm, "SRO_Search_Add"



End Sub
 
.text didnt work but the answer from from wh00t
worked

thanks a lot to both of you for your help
 
Here is a good utility I think I picked up on this site..
You can pass any data type into this function to find out if there is anything in it.

Code:
Function IsNothing(varToTest As Variant) As Integer
'  Tests for a "logical" nothing based on data type
'  Empty and Null = Nothing
'  Number = 0 is Nothing
'  Zero length string is Nothing
'  Date/Time is never Nothing

    IsNothing = True

    Select Case VarType(varToTest)
        Case vbEmpty
            Exit Function
        Case vbNull
            Exit Function
        Case vbBoolean
            If varToTest Then IsNothing = False
        Case vbByte, vbInteger, vbLong, vbSingle, vbDouble, vbCurrency
            If varToTest <> 0 Then IsNothing = False
        Case vbDate
            IsNothing = False
        Case vbString
            If (Len(varToTest) <> 0 And varToTest <> " ") Then IsNothing = False
    End Select

End Function
 
Try this :

Private Sub SelectSRO_Click()

If isnull(Me!SearchOperations.Value) Then
MsgBox "There is no value"
else

If Me!SearchOperations.Value = "" Then
MsgBox "There is no value"
Else
MsgBox "Please enter or select " + "'" + Me!
SearchOperations.Value
End If
endif

DoCmd.Close acForm, "SRO_Search_Add"
 

Users who are viewing this thread

Back
Top Bottom