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
|
|||
|
|||
Understanding the Object Model
Working with forms, I constantly find it difficult to "locate" an object
using vba. Can someone help me understanding the "path" to certain objects? For example: A Main Form (frmMain) with a Tabbed control (tabControl) with Subforms (frmSub1, frmSub2, etc.) on each tab. When I am in a control (txtControl1) on frmSub1 and I want to reference a value in a control (txtControl2) on frmSub2, I try typing a variety of "paths" in my code editor but I can't find the right combination. I have tried using page control names (pgeControl1, pgeControl2, etc.) also but it still doesn't work. Logically it seems that it should be: Me.Parent.tabControl.pgeControl2.frmSub2.txtContro l2 OR Forms.frmMain.tabControl.pgeControl2.frmSub2.txtCo ntrol2 Please help me understand this! Thanks! -- --- TraciAnn Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...esign/200906/1 |
#2
|
|||
|
|||
Understanding the Object Model
All you need is
Forms!MainFormName!SubFormControlName!Form!Control Name Note that the SubFormControlName is NOT the name of the form being used as a subform. It is the name of the subform control on the main form. It is the Source Object property of the subform control that binds the subform to the control. -- Dave Hargis, Microsoft Access MVP "TraciAnn via AccessMonster.com" wrote: Working with forms, I constantly find it difficult to "locate" an object using vba. Can someone help me understanding the "path" to certain objects? For example: A Main Form (frmMain) with a Tabbed control (tabControl) with Subforms (frmSub1, frmSub2, etc.) on each tab. When I am in a control (txtControl1) on frmSub1 and I want to reference a value in a control (txtControl2) on frmSub2, I try typing a variety of "paths" in my code editor but I can't find the right combination. I have tried using page control names (pgeControl1, pgeControl2, etc.) also but it still doesn't work. Logically it seems that it should be: Me.Parent.tabControl.pgeControl2.frmSub2.txtContro l2 OR Forms.frmMain.tabControl.pgeControl2.frmSub2.txtCo ntrol2 Please help me understand this! Thanks! -- --- TraciAnn Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...esign/200906/1 |
#3
|
|||
|
|||
Understanding the Object Model
Tab controls *do not* participate in the "path" for referencing controls on
a form. They are not "containers" the way a subform is. So you ignore a tab control when referencing a control on that tab page. For example, if you have TextBox1 on page 1 of the tabControl, and TextBox2 on page 5 of the tabControl, you reference them this way from the main form: Me.TextBox1 Me.TextBox2 From a subform on the main form, you'd use Me.Parent.TextBox1 Me.Parent.TextBox2 Thus, using your posted example: Me.Parent.frmSub2.Form.txtControl2 or Me.Parent!frmSub2!txtControl2 The above assumes that the name of the subform control on the main form (the control that holds the subform object) is named frmSub2. Note that the name of the subform control may or may not be the same name as its Source Object (which is the actual name of the form that is being used as the subform). -- Ken Snell MS ACCESS MVP http://www.accessmvp.com/KDSnell/ "TraciAnn via AccessMonster.com" u50702@uwe wrote in message news:98087b7efe46a@uwe... Working with forms, I constantly find it difficult to "locate" an object using vba. Can someone help me understanding the "path" to certain objects? For example: A Main Form (frmMain) with a Tabbed control (tabControl) with Subforms (frmSub1, frmSub2, etc.) on each tab. When I am in a control (txtControl1) on frmSub1 and I want to reference a value in a control (txtControl2) on frmSub2, I try typing a variety of "paths" in my code editor but I can't find the right combination. I have tried using page control names (pgeControl1, pgeControl2, etc.) also but it still doesn't work. Logically it seems that it should be: Me.Parent.tabControl.pgeControl2.frmSub2.txtContro l2 OR Forms.frmMain.tabControl.pgeControl2.frmSub2.txtCo ntrol2 Please help me understand this! Thanks! -- --- TraciAnn Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...esign/200906/1 |
#4
|
|||
|
|||
Understanding the Object Model
I have found that this chart is worth printing out and keeping close to my
'puter. http://www.mvps.org/access/forms/frm0031.htm It answers all my questions about forms/subforms syntax. Damon "TraciAnn via AccessMonster.com" u50702@uwe wrote in message news:98087b7efe46a@uwe... Working with forms, I constantly find it difficult to "locate" an object using vba. Can someone help me understanding the "path" to certain objects? For example: A Main Form (frmMain) with a Tabbed control (tabControl) with Subforms (frmSub1, frmSub2, etc.) on each tab. When I am in a control (txtControl1) on frmSub1 and I want to reference a value in a control (txtControl2) on frmSub2, I try typing a variety of "paths" in my code editor but I can't find the right combination. I have tried using page control names (pgeControl1, pgeControl2, etc.) also but it still doesn't work. Logically it seems that it should be: Me.Parent.tabControl.pgeControl2.frmSub2.txtContro l2 OR Forms.frmMain.tabControl.pgeControl2.frmSub2.txtCo ntrol2 Please help me understand this! Thanks! -- --- TraciAnn Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...esign/200906/1 |
#5
|
|||
|
|||
Understanding the Object Model
Me.Parent.frmSub2.Form.txtControl2
Me.Parent!frmSub2!txtControl2 The above assumes that the name of the subform control on the main form (the control that holds the subform object) is named frmSub2. Note that the name of the subform control may or may not be the same name as its Source Object (which is the actual name of the form that is being used as the subform). Okay. I understand everything you said, including the difference between the subform control and the source object name. As a result, I'm still hung up on a couple things. 1. your samples above point to the exact same control but the first, using period separators, includes "Form" whereas the second, using exclamation separators, excludes "Form". Why the difference? 2. It appears that the name of my subform control and the source object name is always the same. I don't do it intentionally, I simply follow a naming procedure for all my objects. Is there a way to tell for sure the names of each? When in design mode I click once on the subform of which the name appears in the Property sheet Selection Type combobox. The Data tab "Source Object" and the Other tab "Name" have the same value. I assume the value in "Source Object" is the name of the Form (as listed in Access Objects) and "Name" is the name of the control, or the container that is holding the form. If this is the case and understanding the answers are purely subjective, am I adhering to good development practices? is there a better way? Thanks Ken and Klatuu for your time! -- --- TraciAnn Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...esign/200906/1 |
#6
|
|||
|
|||
Understanding the Object Model
Damon and Piet,
Thank you! Good idea! It's hanging on my cube now! Although I've referenced this before, I was still a little baffled by the Tab control and Page Control, thinking that this document did not take into consideration that a person is using the tab control. So I was trying to put one or both of the controls in my references. It sure does help to have this newsgroup as a resource! Thanks Again! -- --- TraciAnn Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...esign/200906/1 |
#7
|
|||
|
|||
Understanding the Object Model
Answers inline...
-- Ken Snell MS ACCESS MVP http://www.accessmvp.com/KDSnell/ "TraciAnn via AccessMonster.com" u50702@uwe wrote in message news:9809ed907c1ba@uwe... Me.Parent.frmSub2.Form.txtControl2 Me.Parent!frmSub2!txtControl2 The above assumes that the name of the subform control on the main form (the control that holds the subform object) is named frmSub2. Note that the name of the subform control may or may not be the same name as its Source Object (which is the actual name of the form that is being used as the subform). Okay. I understand everything you said, including the difference between the subform control and the source object name. As a result, I'm still hung up on a couple things. 1. your samples above point to the exact same control but the first, using period separators, includes "Form" whereas the second, using exclamation separators, excludes "Form". Why the difference? Using the . syntax means that the syntax is referring to properties of the form. In order for you to refer to a property of the subform form itself (the form that is the subform), one needs to use the .Form property of the subform control. However, if you use the ! syntax, then you're referring to the default collection of the preceding object, which for form's and subform control's is the Controls collection. Therefore, when you use ! after the subform control, it means to refer to the Controls collection of the form that is the subform, and there is no need to reference the control on the subform through the Form property. 2. It appears that the name of my subform control and the source object name is always the same. I don't do it intentionally, I simply follow a naming procedure for all my objects. Is there a way to tell for sure the names of each? The SourceObject property of the subform control will be the actual name of the form that is being used as the subform. The Name property of the subform control is the name of the subform control. ACCESS will default the two properties to be the same when you drag a form (to be the subform) onto a form in design view. It's ok if they're the same name so long as you remember that they are not the same property. When in design mode I click once on the subform of which the name appears in the Property sheet Selection Type combobox. The Data tab "Source Object" and the Other tab "Name" have the same value. I assume the value in "Source Object" is the name of the Form (as listed in Access Objects) and "Name" is the name of the control, or the container that is holding the form. If this is the case and understanding the answers are purely subjective, am I adhering to good development practices? is there a better way? Thanks Ken and Klatuu for your time! -- --- TraciAnn Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...esign/200906/1 |
Thread Tools | |
Display Modes | |
|
|