Full Version: LostFocus event combo box
UtterAccess Forums > Microsoft Access > Access Forms
jonnyuk3
Hi,
I have a combo box with a list of values in. When i leave the combo box, if a user has not selected anything from the box i want to return an error message. How do i test for a null value?
This is my code at the moment:
CODE
Private Sub cboID_LostFocus()  
    If Me.cboID = Null Then
        ' do something
    Else
        ' do something else
    End If
End Sub

Ocan get to the 'do something else' part if a value is entered, but i cant get to the 'do something' part if no value is entered.
jonnyuk3
strive4peace
Hi Jonny,
It is best to use the form BeforeUpdate event to validate data

Record Validation
http://www.utteraccess.com/forums/showflat...p;Number=725009

~~~

this is not right:
If Me.cboID = Null then

Null is NOT a value, therefore you cannot compare this way

do this -->
If IsNull(me.controlname) then
jonnyuk3
Hi,
Thanks for the info. That works great.
jonnyuk3
strive4peace
you're welcome, Jonny wink.gif happy to help
color="green"]'`[color="orange"],,`[color="pink"],,[color="blue"]`[color="yellow"],
[color="blue"]Wel[color="brown"]come [color="green"]to [color="blue"]U[color="black"]tter [color="blue"]A[color="black"]ccess !
[color="green"],,[color="orange"]`,,[color="pink"]`[color="blue"],,[color="yellow"]`
[color="purple"]
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.