Setting the focus on an object on a sub-form

R

rich

Hello,

I am trying to validate a date on a sub-form. If the validation fails, the
date field should be reset to an empty string and the focus set to that date
field so user can re-enter a valid date. Problem is, Access says it cannot
find the sub-form. Code is below with error line indicated by ==>

Private Sub AccessVerifiedDate_AfterUpdate()

If AccessVerified = False Then
MsgBox ("You must first check the Access Verified checkbox before
you can enter a Verified Date."), vbOKOnly
AccessVerifiedDate = ""
End If
Do While (AccessVerifiedDate <= txtEmplStartDate)
If AccessVerifiedDate <= txtEmplStartDate Then
MsgBox ("The Access Verified Date must occur after the
employee's ARF submission date. Please re-enter the date.")
End If
AccessVerifiedDate = ""
==> [Forms]![SfrmEmplApplMapping].AccessVerifiedDate.SetFocus
Loop

End Sub


The error message is:
Run-time error '2450'
.......can't find the form 'SfrmEmplApplMapping' referred to in a macro
expression of Visual Basic code. If refers to the sub-form.


Can anyone tell me what I am doing wrong?

Thanks,
rich
 
M

Marshall Barton

rich said:
I am trying to validate a date on a sub-form. If the validation fails, the
date field should be reset to an empty string and the focus set to that date
field so user can re-enter a valid date. Problem is, Access says it cannot
find the sub-form.
[Forms]![SfrmEmplApplMapping].AccessVerifiedDate.SetFocus


subfoirms are not open in their own right so they are not
members of the Forms collection. You need to go through the
main form and the subform control's Form property to get to
a control in the subform:

Me.SfrmEmplApplMapping.SetFocus
Me.SfrmEmplApplMapping.Form.AccessVerifiedDate.SetFocus
 
M

Maurice

You are referring a couple of times to the [AccessVerifiedDate] field. The
first time you are referring directly to it and where the problem lies you
are referring to it via a subform reference?

If that's the only place where you have the problem then put the main form
name as wel something like:
[Forms]![mainform]![SfrmEmplApplMapping].AccessVerifiedDate

but since it's an afterupdate event i think you can refer to it directly as:

me.AccessVerifiedDate.setfocus

hth
 

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