SetFocus in a subform, new wrinkle

G

Guest

Ken Snell's instructions to Andy in 'SetFocus in a subform' make sense, but I
am having trouble implementing them. My form has a subform placeholder
subDetail which is populated based upon a dialog box selection. My code
successfully populates the placeholder when intDetailType = 1 (only option
tested). It encouters an error from the .SetFocus instruction, "Run-time
error '2210': Microsoft Office Access can't move the focus to the control
subDetail." I can tab to or click on the subform control, but that is
inelegant (and inefficient for the user). When I reset the code and rerun
the dialog box, it sets the focus correctly. Please help!

With subDetail
Select Case intDetailType
Case 1
.SourceObject = "fsubFlight_entry"
.SetFocus
!txtConfirmation.SetFocus
Case 2
.SourceObject = "fsubRCarHotel"
Case Else
MsgBox "Not defined"
End Select
.Visible = True
End With
 
G

Guest

Try this, change this line
!txtConfirmation.SetFocus

To
!Form.txtConfirmation.SetFocus
 
K

Ken Snell [MVP]

Assuming that subDetail is the name of the subform control (the control that
holds the subform object), one problem is that you're assigning the Source
Object and then immediately trying to set focus to the subform control; you
may have a timing problem. Also, you're not making the subform visible until
after you try to set focus to it; that will not work.

Try this:

With Me.subDetail
Select Case intDetailType
Case 1
.SourceObject = "fsubFlight_entry"
.Visible = True
DoEvents
.SetFocus
.Form.txtConfirmation.SetFocus
Case 2
.SourceObject = "fsubRCarHotel"
.Visible = True
DoEvents
Case Else
MsgBox "Not defined"
End Select

End With
 
G

Guest

..visible was the key! Thanks!

Ken Snell said:
Assuming that subDetail is the name of the subform control (the control that
holds the subform object), one problem is that you're assigning the Source
Object and then immediately trying to set focus to the subform control; you
may have a timing problem. Also, you're not making the subform visible until
after you try to set focus to it; that will not work.

Try this:

With Me.subDetail
Select Case intDetailType
Case 1
.SourceObject = "fsubFlight_entry"
.Visible = True
DoEvents
.SetFocus
.Form.txtConfirmation.SetFocus
Case 2
.SourceObject = "fsubRCarHotel"
.Visible = True
DoEvents
Case Else
MsgBox "Not defined"
End Select

End With
 

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