Setting focus on a subform control

srobbins

Registered User.
Local time
Today, 07:17
Joined
Jun 25, 2006
Messages
11
On my main form I have a combobox with logic in the afterupdate event to add a record to a table. That table is the source for a subform.
Here's what I'm doing in the afterupdate event:
1. Append a record to TableA.
2. Requery the subform (which is a list of TableA).
3. Set focus to a specific control of the new record (always the last record) in the subform.

The first two steps work perfectly, but I'm having a problem with getting the focus set. No error message, but it doesn't work. The focus remains in the combobox.

Here's my code, which is at the very end of the combobox update event, after the requery:
With Me.mySubform
.Form.Recordset.MoveFirst
For i = 0 To .Form.Recordset.RecordCount - 1
If intI = .Form.Recordset.RecordCount - 1 Then
.Form.Controls("QuantityReceived").SetFocus
Exit For
End If
.Form.Recordset.MoveNext
Next i
End With

Am hoping someone can tell me what I've overlooked.
 
The syntax for referring to a control on a subform is:

Code:
Forms!YourMainFormNameHere.YourSubformNameHere.Form.YourControlNameHere

IMPORTANT NOTE: The part that says 'YourSubformNameHere' has to be the name of the CONTROL that houses the subform. Usually, if you use the wizard to do add the subform, the name of the control is by default the name of the subform. But, it can be different, so just make sure that you use the subform container's name.
 

Users who are viewing this thread

Back
Top Bottom