A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Setting focus to a control on a subform on opening



 
 
Thread Tools Display Modes
  #1  
Old July 14th, 2004, 04:34 AM
John S. Ford, MD
external usenet poster
 
Posts: n/a
Default 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  
Old July 14th, 2004, 05:28 AM
Allen Browne
external usenet poster
 
Posts: n/a
Default 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  
Old July 14th, 2004, 06:27 AM
John S. Ford, MD
external usenet poster
 
Posts: n/a
Default 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  
Old July 14th, 2004, 06:36 AM
Allen Browne
external usenet poster
 
Posts: n/a
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 02:08 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.