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.
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
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
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
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
If Nz(Me!txtBox,"")<>"" Then
' is not null or empty
else
' is either null or empty
end if
mike
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
If Nz(Me!txtBox,"")<>"" Then
' is not nuul or empty
Else
' it is either empty or null
End if
Mike