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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check control to see if data was entered 1

Status
Not open for further replies.

TheVMan

IS-IT--Management
Feb 19, 2001
110
US
I'm trying to trap errors, such as whether or not a user actually entered a value in a text box that is passed to a query. For example, the control txtControl had no data entered, and when the user hits the next button my code looks like this:

Dim stDocName As String
Dim stLinkCriteria As String
Dim stEmptyString As String

stDocName = "frmInfo"
stEmptyString = Me!txtControl

If stEmptyString = "" Then
MsgBox "Please enter a value or choose a different Entry Method", vbOKOnly
Else
stLinkCriteria = "[Column]=" & Me![txtControl]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

I usually get an "Invalid Use of Null" error, but sometimes (somehow) it displays my message box the way I'd expect to see it. Weird. Thanks in advance.

V
 
When a control has no data in it, even a text box, its value is not an empty string (""). Its value is Null, and there are many things you can't do with a Null value. You're getting an error when you try to assign the Null value to stEmptyString, which can only hold strings.

To check for a Null value, use the IsNull(controlname) function.

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmInfo"

If IsNull(Me!txtControl) Then
MsgBox "Please enter a value or choose a different Entry Method", vbOKOnly
Else
stLinkCriteria = "[Column]=" & Me![txtControl]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top