what is wrong with this code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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
 
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
 

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

Back
Top