Set field focus in a subroutine

G

gaugust

In Access 2003 (Windows XP) I am passing the value of a field in a textbox on
a form to a subroutine to validate that the date value is within a range. If
the date is out of range I would like to set the focus of the field on the
form and display an error message. When I pass in the field to the
subroutine, I get a compile error "Invalid qualifier" when I try to set focus
to the date field. How can I set the focus to the field within the
subroutine. Here is the subrotuine code:

Public Sub CheckDates(date1 As Date)
If Not IsNull(date1) And date1 < [Forms]![frmMRA]![frmSectionA -
1].Form![date_of_admission].Value Then
MsgBox "The date must be on or after the hospital admission date",
vbOKOnly, "Date out of range"
Cancel = True
date1.SetFocus
End If
End Sub
 
M

Marshall Barton

gaugust said:
In Access 2003 (Windows XP) I am passing the value of a field in a textbox on
a form to a subroutine to validate that the date value is within a range. If
the date is out of range I would like to set the focus of the field on the
form and display an error message. When I pass in the field to the
subroutine, I get a compile error "Invalid qualifier" when I try to set focus
to the date field. How can I set the focus to the field within the
subroutine. Here is the subrotuine code:

Public Sub CheckDates(date1 As Date)
If Not IsNull(date1) And date1 < [Forms]![frmMRA]![frmSectionA -
1].Form![date_of_admission].Value Then
MsgBox "The date must be on or after the hospital admission date",
vbOKOnly, "Date out of range"
Cancel = True
date1.SetFocus
End If
End Sub


Where is that code called from? The use of Cancel is
invalid so I suspect that you need to do more than just look
at this one procedure,

date1 declared as a date **value**, but the SetFocus line is
trying to use it as a control object. This part of your
problems needs to declare it as a control:

Public Sub CheckDates(date1 As Control)

but that may or may not impact something in the code that
calls the procedure.
 

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

Top