Runtime Error "Invalid use of Null"

G

Guest

I have a form that uses an event procedure to lookup the name when a loan
number is entered. I need a message to display when the loan number is left
blank that says "You must enter a Loan #", but instead I get a runtime error
94 "Invalid use of null". This is the code I am using for the event
procedure. What do I need to change?

Option Compare Database

Private Sub FindLoan_Click()
On Error GoTo Err_FindLoan_Click


Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_FindLoan_Click:
Exit Sub

Err_FindLoan_Click:
MsgBox Err.Description
Resume Exit_FindLoan_Click

End Sub

Private Sub ExitFrm_Click()
On Error GoTo Err_ExitFrm_Click


DoCmd.Close

Exit_ExitFrm_Click:
Exit Sub

Err_ExitFrm_Click:
MsgBox Err.Description
Resume Exit_ExitFrm_Click

End Sub

Private Sub Loan__BeforeUpdate(Cancel As Integer)
Dim varLoanNum As String
Dim strMsg As String

If IsNull(varLoanNum) Then
strMsg = "You Must Enter Loan Number"
End If

End Sub

Private Sub Loan__Exit(Cancel As Integer)
Dim varBorrower As String
Dim varLoanNum As String
Dim strMsg As String

varBorrower = DLookup("[Borrower]", "LoanNum Tbl", "[Loan Num] = [Loan#]")
If (Not IsNull(varBorrower)) Then Me![Borrower] = varBorrower


End Sub

Private Sub NewRcrd_Click()
On Error GoTo Err_NewRcrd_Click


DoCmd.GoToRecord , , acNewRec


Exit_NewRcrd_Click:
Exit Sub

Err_NewRcrd_Click:
MsgBox Err.Description
Resume Exit_NewRcrd_Click

End Sub
Private Sub Command53_Click()
On Error GoTo Err_Command53_Click


DoCmd.GoToRecord , , acNewRec


Exit_Command53_Click:
Exit Sub

Err_Command53_Click:
MsgBox Err.Description
Resume Exit_Command53_Click

End Sub
 
A

Armen Stein

Private Sub Loan__BeforeUpdate(Cancel As Integer)
Dim varLoanNum As String
Dim strMsg As String

If IsNull(varLoanNum) Then
strMsg = "You Must Enter Loan Number"
End If

End Sub
 
G

Guest

Thank you. That solved getting the Runtime error but I am still not able to
display a message when no loan number is entered. I have a number of people
who will be using this form and the loan number is my key field to pull
information for reports. When I enter no loan number I get the previous
borrower or if I'm starting with a blank screen I get nothing and no message
to the user to enter the loan number. This is the modification I have made
to the code.


Private Sub Loan__Exit(Cancel As Integer)
Dim varBorrower As Variant
Dim varLoanNum As Variant
Dim strMsg As String

If IsNull(varLoanNum) Then
strMsg = "You Must Enter Valid Loan Number"

End If

varBorrower = DLookup("[Borrower]", "LoanNum Tbl", "[Loan Num] = [Loan#]")
If (Not IsNull(varBorrower)) Then Me![Borrower] = varBorrower


End Sub

Private Sub Loan__NotInList(NewData As String, Response As Integer)
Dim varLoanNum As Variant
Dim strMsg As String

If IsNull(varLoanNum) Then
strMsg = "You Must Enter Valid Loan Number"
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Display message on form 3
Jet Engine Error Message 2
Access Pop-Up Calendar 2
lock button 15
Checking for Null 2
Outlook events stop work randomly 0
search command 2
Compile error- Invalid use of property 2

Top