what is wrong with this code

A

Al

I am trying to write a global code that detects any missing value that I
specify in the argument. I am getting error messages with the following code:
Call MissingVal(Parent.[DateofExam], "Date of Exam", Me)

Function MissingVal(Val, fldName As String, frm As Form) As Integer
If Not IsNull(Val) Then
MissingVal = 1
Else
MissingVal = 0
MsgBox "You must enter " & fldName
frm.Undo
frm.fldName.SetFocus

End If

End Function
 
A

Al

Run-time error 2465
application-defined or object-defined error
Al

Douglas J. Steele said:
What's the error message you're getting?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Al said:
I am trying to write a global code that detects any missing value that I
specify in the argument. I am getting error messages with the following
code:
Call MissingVal(Parent.[DateofExam], "Date of Exam", Me)

Function MissingVal(Val, fldName As String, frm As Form) As Integer
If Not IsNull(Val) Then
MissingVal = 1
Else
MissingVal = 0
MsgBox "You must enter " & fldName
frm.Undo
frm.fldName.SetFocus

End If

End Function
 
A

Al

the line that is triggering the error is:
frm.fldName.SetFocus

Douglas J. Steele said:
What's the error message you're getting?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Al said:
I am trying to write a global code that detects any missing value that I
specify in the argument. I am getting error messages with the following
code:
Call MissingVal(Parent.[DateofExam], "Date of Exam", Me)

Function MissingVal(Val, fldName As String, frm As Form) As Integer
If Not IsNull(Val) Then
MissingVal = 1
Else
MissingVal = 0
MsgBox "You must enter " & fldName
frm.Undo
frm.fldName.SetFocus

End If

End Function
 
K

Klatuu

Since fldName is a string, you will have to change the syntax, see below.
Also, Val is a VBA function name. I would recommend you change it and avoid
using any Access reserved words. It can cause some hard to trace problems.
To avoid this possiblity, it is always a good idea to use good naming
conventions. Here is a site that may help you with that:

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnaraccess/html/msdn_20naming.asp

Function MissingVal(Val, fldName As String, frm As Form) As Integer
If Not IsNull(Val) Then
MissingVal = 1
Else
MissingVal = 0
MsgBox "You must enter " & fldName
frm.Undo
frm.Controls(fldName).SetFocus

End If

End Function

Al said:
the line that is triggering the error is:
frm.fldName.SetFocus

Douglas J. Steele said:
What's the error message you're getting?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Al said:
I am trying to write a global code that detects any missing value that I
specify in the argument. I am getting error messages with the following
code:
Call MissingVal(Parent.[DateofExam], "Date of Exam", Me)

Function MissingVal(Val, fldName As String, frm As Form) As Integer
If Not IsNull(Val) Then
MissingVal = 1
Else
MissingVal = 0
MsgBox "You must enter " & fldName
frm.Undo
frm.fldName.SetFocus

End If

End Function
 
Top