How do I move focus to a control in a nested subform ?

M

medirate

I need to move to a control(txtDIA) located in a nested subform. The nested
subform (subPatient) is located inside subform subPatientInfo, which is
located inside frmPatientInfo. I open frmPatientInfo by closing another
form, frmNotes.



frmPatientInfo, has the following properties:

Name Source
Object

Main form: frmPatientInfo

Sub form: subPatientInfo fsubPatientInfo

Nested in subform: subPatient fsubPatient



So on the on Close event for frmNotes, I have the following code:



Private Sub Form_Close()

Dim frm1 As Form

Dim frm2 As Form

Dim rst1 As Recordset

Dim rst2 As Recordset



DoCmd.OpenForm "frmPatientInfo", , , "[fldCompanyID]= " &
Me![Retain_CompanyID], acFormPropertySettings, acWindowNormal



Set frm1 = Forms!frmPatientInfo!subPatientInfo.Form

Set frm2 = Forms!frmPatientInfo!subPatientInfo.Form!SubPatient.Form



Set rst1 = frm1.Recordset

Set rst2 = frm2.Recordset



With rst1

.FindFirst "fldPatientID = " & Me.Retain_PatientID

If .NoMatch Then

MsgBox "Could not locate the Patient ID number"

Else

frm1.Bookmark = rst1.Bookmark

End If

End With



With rst2

..FindFirst "fldLossID = " & Me.Retain_LossId

If .NoMatch Then

MsgBox "Could not locate the Loss Id number"

Else

frm2.Bookmark = rst2.Bookmark

End If

End With



Forms!frmPatientInfo!subPatientInfo.Form!SubPatient.SetFocus

Forms!frmPatientInfo!subPatientInfo.Form!SubPatient!txtDIA.SetFocus



End Sub



When frmNotes closes, frmPatientInfo opens up fine and dandy, but the focus
will not move to the txtDIA control on the nested subform. Instead, the
focus remains in the Main form. There are no errors generated.



I've also tried setting the focus by referring to the nested subform as
'frm2.SetFocus' right after 'frm2.Bookmark' in the above code, but this
generated "Error 244: There is an invalid method in the expression".



How can I move the focus to the txtDIA control once the form is opened?



Thanks!
 
G

Guest

I think you need one more qualification, like this:

Forms!frmPatientInfo!subPatientInfo.Form!SubPatient!Form!txtDIA.SetFocus

I added another !Form toward the end, which indicates that you want Access
to look at the source object (fsubPatient) of SubPatient.

Barry
 
A

Albert D. Kallal

You have to move the focis to the sub-form first..

Try

frm1.setfocus
frm2.setfocus

If the above don't work, then you can try fully qualified references.

Forms!frmPatientInfo!subPatientInfo.SetFocus

Forms!frmPatientInfo!subPatientInfo.Form!SubPatient.SetFocus

Forms!frmPatientInfo!subPatientInfo.Form!SubPatient!LastName.SetFocus

So, move the focus to the sub-form first, and THEN set the focus to the
field you want....
 

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