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

Invalid Use of Null (IF..THEN)

Status
Not open for further replies.

BigC666

IS-IT--Management
Mar 20, 2002
20
0
0
MX
Here is my code...

Private Sub Authorize_Click()
On Error GoTo Err_Authorize_Click

Dim Field As String
Dim Check As Boolean

Field = Me!AuthorizationNumber
Check = IsNull(Field)

If (Check = True) Then
Randomize
Me!AuthorizationNumber = Int(RND * 1000000000)
Else
MsgBox "This Ticket Has Already Been Authorized"
GoTo Exit_Authorize_Click

End If

Exit_Authorize_Click:
Exit Sub

Err_Authorize_Click:
MsgBox Err.Description
Resume Exit_Authorize_Click

End Sub

If there is a value in the AuthorizationNumber Field then the msgbox displays if there is no value I get The Invalid Use of Null Error. What am I doing wrong? Any help would be greatly appreciated.
 
In your Sub you try to evaluate the variable Field of type String. As far as I know a String cannot become a Null.
A control, like Me!AuthorizationNumber can.

Try:
Dim Check As Boolean

Check = IsNull(Me!AuthorizationNumber)

The function IsNull returns a true or a false. True if the variable o be evaluated is a Null, false if the variable to be evaluated in not a Null.

Think it will do the job.

Good luck, Bart V.
 
Private Sub Authorize_Click()
On Error GoTo Err_Authorize_Click




Field = Me!AuthorizationNumber
Field1 = Me!TicketID

If IsNull(Field) = True And IsNull(Field1) = False Then
Randomize
Me!AuthorizationNumber = Int(RND * 1000000000)
Else
MsgBox "This Ticket Has Already Been Authorized"
GoTo Exit_Authorize_Click

End If

Exit_Authorize_Click:
Exit Sub

Err_Authorize_Click:
MsgBox Err.Description
Resume Exit_Authorize_Click

End Sub

This is what I used to get it to work. Any other tips will be welcomed with open arms. Thank you for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top