UtterAccess.com
We have detected that you are using an unsupported web browser. We recommend you to upgrade your web browser to get the most from UtterAccess forums.
Why should and how can I upgrade?
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> SetFocus on Control in Subform, Office 2010    
 
   
troyccp1
post Nov 3 2010, 09:26 AM
Post #1

New Member
Posts: 7



I have a main form (frmMain) which has a Navigation Subform (tabs across the top). One of those tabs is Beginning of Day. When that tab is clicked, it loads the subform frmBeginningofDay. The subform frmBeginningofDay has a control txtSearch that I want to set focus on when the form loads.
can use txtSearch.SetFocus to successfully set focus on that control when frmBeginningofDay loads by itself, but this doesn't work when it loads within the frmMain. I believe I need to first set focus on the subform, and then set focus to the control, but I just can't get the syntax correct. Whenever I use the frmBeginningofDay in my Event Procedure code it says it either can't find that form or that control.
I've tried many iterations, but here is one example:
' Select the main form.
Forms![frmMain].SetFocus
' Select the subform control.
Forms![frmMain]![NavigationSubform]![frmBeginningofDay].SetFocus
Thanks in advance for the help, this is my first post on these forums.
Go to the top of the page
 
+
jhcarrell
post Nov 3 2010, 09:40 AM
Post #2

UtterAccess Veteran
Posts: 481
From: Birmingham, Alabama



Have you tried adding SetFocus event to the tab that opens the subform?
Go to the top of the page
 
+
Alan_G
post Nov 3 2010, 09:41 AM
Post #3

Utterly Yorkshire and Forum/Wiki Editor
Posts: 16,135
From: Devon UK



Hi
Welcome to UtterAccess welcome2UA.gif
It's a two stage process. As you said, you need to set the focus to the subform control first, then the control on the subform. If you were using the Open or Load event of frmMain, it would be along the lines of
CODE
Me.NavigationSubform.SetFocus
Me.NavigationSubform.Form!txtSearch.SetFocus
Go to the top of the page
 
+
troyccp1
post Nov 3 2010, 10:36 AM
Post #4

New Member
Posts: 7



Thanks for both of your fast responses.
hcarrell, I hadn't thought about that option. I'll try that out.
Alan_G, I don't want to set focus on open or load of frmMain, because that has many tabs and subforms, each of which will need focus when they load. What I'd like to do is set the focus when I click on the Beginning of Day tab and the subform loads. I'm trying to do it right now in the On Load event of the frmBeginningofDay.
Go to the top of the page
 
+
Alan_G
post Nov 3 2010, 10:50 AM
Post #5

Utterly Yorkshire and Forum/Wiki Editor
Posts: 16,135
From: Devon UK



Hi
Just move the code I posted to the Change event of the Tab Control wrapped in an If/Then construct. Each page of the Tab Control has a numerical value, so if the Beginning of Day tab has a value of say 2, then the Change event would look like
CODE
If Me.NameOfTabControl = 2 Then
   Me.NavigationSubform.SetFocus
   Me.NavigationSubform.Form!txtSearch.SetFocus
End If
Go to the top of the page
 
+
troyccp1
post Nov 3 2010, 11:06 AM
Post #6

New Member
Posts: 7



By the numerical value of the Tab Control, do you mean the Tab Index number? That is the only number I see like this in the property sheet. It has a tab index of 1, and is the second tab, so I've tried 1 and 2, but neither seem to work.
ere's my code:
CODE
Private Sub tabBeginningofDay_Click()
If Me.tabBeginningofDay = 1 Then
Me.NavigationSubform.SetFocus
Me.NavigationSubform.Form!txtSearch.SetFocus
End If
End Sub

Oget the error:
Run time error '483'
Object doesn't support this property or method
Thanks again.
Go to the top of the page
 
+
Alan_G
post Nov 3 2010, 11:08 AM
Post #7

Utterly Yorkshire and Forum/Wiki Editor
Posts: 16,135
From: Devon UK



Hi
You need to use the Change event, not the Click <
Go to the top of the page
 
+
troyccp1
post Nov 3 2010, 11:22 AM
Post #8

New Member
Posts: 7



Ok, there isn't an On Change option in the property sheet for the Navigation Control, so that's why I tried On Click.
On the VB, I changed it to Change and it's not erroring out any longer. However, it's not working. But I'm trying some different ways to reference it.
Go to the top of the page
 
+
Alan_G
post Nov 3 2010, 11:28 AM
Post #9

Utterly Yorkshire and Forum/Wiki Editor
Posts: 16,135
From: Devon UK



Hi
The Change event is one of the events of the Tab Control itself. I'm not sure what you mean by 'Navigation Control' ?
Go to the top of the page
 
+
troyccp1
post Nov 3 2010, 11:44 AM
Post #10

New Member
Posts: 7



It's a Navigation Form I created in Access 2010. It's the Horizontal Tabs, 2 Levels flavor.
When I create a new form like this, it creates two rows of tabs. The first row is given Selection Type: Navigation Control in the property sheet and the name is defaulted to NavigationControl0. The second row has the same Selection Type and is given the name NavigationControl5.
I've uploaded a small db file with my forms only it it so you can see what I'm looking at.
Attached File  Database4.zip ( 71.35K ) Number of downloads: 10
Go to the top of the page
 
+
Alan_G
post Nov 3 2010, 11:54 AM
Post #11

Utterly Yorkshire and Forum/Wiki Editor
Posts: 16,135
From: Devon UK



Hi
ha, that may explain it then. Sorry, I don't have A2010 and consequently never heard of a Navigation Form. I was basing my answers on a standard Tab Control that you'd have on a form, which I guess doesn't apply to Navigation Forms.
Perhaps things have changed in A2010, but certainly in previous versions of Access setting the focus to a control on a subform was a two stage process as I outlined above.
Sorry my answers don't apply to you - hopefully someone with A2010 will be along shortly who can give you the answer <
Go to the top of the page
 
+
troyccp1
post Nov 3 2010, 12:09 PM
Post #12

New Member
Posts: 7



Thank you for your time then Alan. I sure hope someone does! I think this is just a fundamental block that if I can figure out the right syntax for this I'll be fine in other areas as well. In other words, I'm having trouble referencing control values in queries too - things work fine when testing in the single form, but when I try them as a subform of the main I can't get it to work right.
Go to the top of the page
 
+
Alan_G
post Nov 3 2010, 01:33 PM
Post #13

Utterly Yorkshire and Forum/Wiki Editor
Posts: 16,135
From: Devon UK



Hi
wouldn't have thought referencing subforms and /or controls on them has changed, so if that's all you need then have a look here for info <
Go to the top of the page
 
+
troyccp1
post Nov 3 2010, 02:09 PM
Post #14

New Member
Posts: 7



Thank you very much again, that reference looks exactly like what I need!
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Search  ·  Go to Top  ·  Lo-Fi Version Time is now: 23rd August 2014 - 12:31 AM