If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Setting focus to a control on a subform on opening
In Access 97, have a form with a subform on it. Upon opening the main
form, I'd like the focus to be immediately set to a textbox on the subform. The name of the subform control (not the actual subform is sbfctlSubForm. (In case it matters, the name of the actual subform that was embedded into the main form is sbfSubForm). I've tried the following which doesn't work: Private Sub Form_Open(Cancel As Integer) Me!sbfctlSubForm.Form!txtControl.SetFocus End Sub What am I doing wrong? John |
#2
|
|||
|
|||
Setting focus to a control on a subform on opening
You have to set focus to the subform control first, before you will see it
set focus to the control in the subform. You may also find that Form_Open is too early. Try: Private Sub Form_Load() Me.sbfctlSubForm.SetFocus Me.sbfctlSubForm.Form!txtControl.SetFocus End Sub -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "John S. Ford, MD" wrote in message ... In Access 97, have a form with a subform on it. Upon opening the main form, I'd like the focus to be immediately set to a textbox on the subform. The name of the subform control (not the actual subform is sbfctlSubForm. (In case it matters, the name of the actual subform that was embedded into the main form is sbfSubForm). I've tried the following which doesn't work: Private Sub Form_Open(Cancel As Integer) Me!sbfctlSubForm.Form!txtControl.SetFocus End Sub |
#3
|
|||
|
|||
Setting focus to a control on a subform on opening
Allan,
That worked perfectly. In fact, since txtControl was the first control in the tab order of my subform, I didn't even need to use the second line of your code. I did test it with other controls on the subform and it worked perfectly as written (when placed in either the OnLoad event or the OnOpen event). I don't need a response but just curious: any idea as to why I couldn't access the textbox focus directly from line two? Is the inability to do that documented in Access 97? Thanks for the help, John |
#4
|
|||
|
|||
Setting focus to a control on a subform on opening
Access keeps track of the control that has focuse in each form
independently, so setting focus to something in the subform without making it the active control in the main form does not achieve what you wanted. -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "John S. Ford, MD" wrote in message ... That worked perfectly. In fact, since txtControl was the first control in the tab order of my subform, I didn't even need to use the second line of your code. I did test it with other controls on the subform and it worked perfectly as written (when placed in either the OnLoad event or the OnOpen event). I don't need a response but just curious: any idea as to why I couldn't access the textbox focus directly from line two? Is the inability to do that documented in Access 97? Thanks for the help, John |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Need help with cascading combos | Tom | Using Forms | 19 | July 1st, 2004 11:11 PM |
How to assign value to a report control? | Peter | General Discussion | 3 | June 29th, 2004 11:17 AM |
Using BeforeUpdate Event to set the focus onto the subform | Joe Joplin | Using Forms | 1 | June 27th, 2004 11:31 PM |
subform - click on control | David Norman | Using Forms | 2 | May 28th, 2004 02:24 AM |