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.
wwstudioincAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike EghtebasDatabase and Application DeveloperCommented:
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
Rey Obrero (Capricorn1)Commented:

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
mpmccarthyCommented:
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
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Rey Obrero (Capricorn1)Commented:


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
Mike EghtebasDatabase and Application DeveloperCommented:
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
Mike EghtebasDatabase and Application DeveloperCommented:
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

Rey Obrero (Capricorn1)Commented:
oh i forgot the msgbox

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
            msgbox  "Value is  required  for "  & me(ctl.name).name
            me(ctl.name).setfocus
            exit sub
           end if
         end if
      end if
next

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rockiroadsCommented:
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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.