Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to test for null values in a textbox on a form

Status
Not open for further replies.

Awarmplace1

Technical User
Nov 29, 2001
11
US
How can I create a macro that will test for null values in text boxes on a form and let me return custom message boxes with they are null. and it will also need to allow me to save the contents on the form after the testing is complete............
 
This may help:

Code is:

Dim ctl As Control
For Each ctl In Me.Controls
'Check to see if control is a text box...
If ctl.ControlType = acTextBox Then
If IsNull....Then
Msgbox '''' do your thing
End If
Next ctl
Exit Sub

This routine just rolls throught the textboxes on the Form. Hope this helps.
 
Adding on to Isadore's post, you can use the tag property of each textbox to customize the operation and the message. For the textboxes you want checked for nulls, set the Tag property to 'req' plus a description of the textbox.

eg: Text1.Tag = "req Arrival Time"
Text2.Tag = "req Departure Time"

Dim ctl As Control
For Each ctl In Me.Controls
'Check to see if control has the req tag...
If Left(ctl.tag, 3) = "req" Then
If nz(ctl,"") = "" Then
Msgbox Mid(ctl.tag, 4) & " is a required field."
End If
Next ctl

This lets you customize the messagebox prompt to identify the missing information as in "Arrival Time is a required field."


HTH
John

Use what you have,
Learn what you can,
Create what you need.
 
Function VerNull()
Dim ctl As Control
Dim ObjectName, strValue, MsgStr As String
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
ObjectName = ctl.Name
strValue = ctl.OldValue
Debug.Print ObjectName
If IsNull(strValue) Then
MsgStr = "Value inside " & ObjectName & " = Empty"
Else
MsgStr = "Value inside " & ObjectName & " = " & strValue
End If
MsgBox MsgStr
End If
Next ctl
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top