Link to home
Start Free TrialLog in
Avatar of wwstudioinc
wwstudioinc

asked on

check null values

I am looking for a function that will check a control for  null values if the control tag is "req'' then use associated label caption to promt the user for an input.
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

suppose you have Me!txtBox

If Nz(Me!txtBox,"")<>"" Then
' is not nuul or empty

Else

' it is either empty or null
End if

Mike
Avatar of Rey Obrero (Capricorn1)

dim ctl as control

for each ctl in me.controls
     If ctl.ControlType = acComboBox Or ctl.ControlType = acTextBox Then
         If InStr(ctl.Tag, "req") > 0 Then
           
            me(ctl.name).setfocus

         end if
      end if
next
Avatar of mpmccarthy
mpmccarthy

This must be on the forms VBA.

If IsNull(Me.Control) Then
    Msgbox "You must enter a value in " & Me.Control] & "." & Chr(13) & _
                "It is a required field", vbOkOnly + vbWarning
    Me.Control.SetFocus
End If


dim ctl as control

for each ctl in me.controls
     If ctl.ControlType = acComboBox Or ctl.ControlType = acTextBox Then
         If InStr(ctl.Tag, "req") > 0 Then
           If IsNull(Me(ctl.Name)) Or Len(Me(ctl.Name)) = 0 Then
            me(ctl.name).setfocus
            exit sub
           end if
         end if
      end if
next
examples:

Me!txtBox = 12
Nz(Me!txtBox,"") = 12
-----------
Me!txtBox = Null
Nz(Me!txtBox,"") = ""  '<-- here, Nz() changes Null to ""
-----------
Me!txtBox = ""    '<-- empty
Nz(Me!txtBox,"") = ""
-----------

Now:

If Nz(Me!txtBox,"")<>"" Then  
 ' is either null or empty
else
 ' is not null or empty
end if
I had to swith... I had it correct on my first post

If Nz(Me!txtBox,"")<>"" Then  
 ' is not null or empty
else
 ' is either null or empty
end if

mike

ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
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
loop like cap has said, in order to find a control with a certain tag value, thats what u have to do

but to prompt, u can use InputBox, note this returns null if no value entered
e.g.

Dim sVal

sVal = InputBox("Enter Value")
If IsNull(sVal) = True Then
    msgbox "No Value Entered"
Else
    msgbox "You entered " & sVal
end if