|
 |
access thread: Checking null text boxes
Message #1 by "Ryan Lockhart" <rlockhart@p...> on Mon, 26 Nov 2001 20:54:38
|
|
I need to check for blank txtboxes. This is my code:
If txtUNO.Value = "" Or txtDOS = "" Then
MsgBox "Fill these in."
Exit Sub
End If
It doesn't catch the null values. In debug mode I can see that the txtbox
is NULL, so I tried setting the condition = NULL. That didn't work
either. Please point in right direction.
Message #2 by "Richard Lobel" <richard@a...> on Mon, 26 Nov 2001 13:31:13 -0800
|
|
Use:
If isnull(txtUNO) Then
MsgBox "Fill these in."
Exit Sub
End If
Or you can combine the null check with the empty string check:
If txtDOS = "" or isnull(txtDOS) Then
MsgBox "Fill these in."
Exit Sub
End If
>I need to check for blank txtboxes. This is my code:
If txtUNO.Value = "" Or txtDOS = "" Then
MsgBox "Fill these in."
Exit Sub
End If
It doesn't catch the null values. In debug mode I can see that the
txtbox
is NULL, so I tried setting the condition = NULL. That didn't work
either. Please point in right direction.<
Richard Lobel
Accessible Data
richard@a... <mailto:richard@a...>
Cell: (xxx) xxx-xxxx
Fax: (xxx) xxx-xxxx
Message #3 by Walt Morgan <wmorgan@s...> on Mon, 26 Nov 2001 15:20:51 -0600
|
|
IsNull Function Example
The following example uses the IsNull function to determine whether the
value of a control is Null. If it is, a message prompts the user to enter
data. If the value is not Null, a message displays the value of the control.
Sub ControlValue(ctlText As Control)
Dim strMsg As String
' Check that control is text box.
If ctlText.ControlType = acTextBox Then
' If value of control is Null, prompt for data.
If IsNull(ctlText.Value) Then
strMsg = "No data in the field '" & ctlText.Name _
& "'." & vbCrLf & "Please enter data for " _
& "this field now."
If MsgBox(strMsg, vbQuestion) = vbOK Then
Exit Sub
End If
' If value is not Null, display value.
Else
MsgBox (ctlText.Value)
End If
End If
End Sub
Message #4 by "John Ruff" <papparuff@c...> on Mon, 26 Nov 2001 14:35:40 -0800
|
|
Ryan,
Another way of checking for null or empty control is
if isnull(txtUno) or len(txtUno)=0 then
msgbox "Fill these in."
txtUno.setfocus
exit sub
endif
If you have multiple textboxes that require checking then you can use
the tag property of each of those textboxes. You can enter something
like ValidateData in the tag property. Then you can loop through all
the controls and if they are textboxes and have ValidateData in their
tag property, you can check for null or empty strings. You would place
the code in the Form's BeforeUpdate event and it would look like this:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
For Each ctl In Controls
' If the control is a textbox and _
it's Tag property has the word ValidateData in it then _
make sure data is in the control
If ctl.ControlType = acTextBox And ctl.Tag = "ValidateData" Then
' If the control is null or has no data, then dispay _
a message telling user to place data in the _
field. Then cancel the update and place the
focus _
on the offending control
If IsNull(ctl) Or Len(ctl) = 0 Then
MsgBox "Please fill in " & ctl.Name
Cancel = True
ctl.SetFocus
Exit Sub
End If
End If
Next ctl
End Sub
John Ruff - The Eternal Optimist :-)
-----Original Message-----
From: Ryan Lockhart [mailto:rlockhart@p...]
Sent: Monday, November 26, 2001 8:55 PM
To: Access
Subject: [access] Checking null text boxes
I need to check for blank txtboxes. This is my code:
If txtUNO.Value = "" Or txtDOS = "" Then
MsgBox "Fill these in."
Exit Sub
End If
It doesn't catch the null values. In debug mode I can see that the
txtbox
is NULL, so I tried setting the condition = NULL. That didn't work
either. Please point in right direction.
---
You are currently subscribed to access as: papparuff@c... To
unsubscribe send a blank email to $subst('Email.Unsub')
|
|
 |