changing control properties at runtime

G

Guest

I have a form with a TabControl (eg. tabControl1) on it. It also has 2 Subform controls on it. At runtime, the Subforms appear to be placed on individual tab pages. Depending on on the value of tabControl1, various properties of on or both of the Subforms are changed

For example

select case tabControl
case
subForm1.Top=1.75 * 144
subForm1.SourceObject="frmMySubform11
subForm1.LinkMasterFields="MasterID11;MasterID12
subForm1.LinkChildFields="ChildID11;ChildID12
case
subForm1.Top=2 * 144
subForm1.SourceObject="frmMySubform12
subForm1.LinkMasterFields="MasterID11
subForm1.LinkChildFields="ChildID11
end selec

Unfortunately, this code works inconsistently. It appears that it might be execution order dependent. In particular, I have had to anticipate an error that is raised because I change the number of link fields in, say, the LinkMasterFields property without simultaneously changing it in the LinkChildFields property (as far as I know, it is not possible to change these properties simultaneously at runtime). I have worked around this one, but another is the repositioning, which sometimes works and sometimes doesn't, and I don't know why

What is wrong with my code? Is there a better way

Thanks

Pat
 
G

Graham Mandeno

Hi Pat

I haven't tried this, so it's just a stab in the dark, but you might find
you can change LinkXXXFields if you first remove the SourceObject:
subForm1.SourceObject=""
subForm1.LinkMasterFields="MasterID11"
subForm1.LinkChildFields="ChildID11"
subForm1.SourceObject="frmMySubform12"

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

pmcguire said:
I have a form with a TabControl (eg. tabControl1) on it. It also has 2
Subform controls on it. At runtime, the Subforms appear to be placed on
individual tab pages. Depending on on the value of tabControl1, various
properties of on or both of the Subforms are changed.
For example:

select case tabControl1
case 0
subForm1.Top=1.75 * 1440
subForm1.SourceObject="frmMySubform11"
subForm1.LinkMasterFields="MasterID11;MasterID12"
subForm1.LinkChildFields="ChildID11;ChildID12"
case 1
subForm1.Top=2 * 1440
subForm1.SourceObject="frmMySubform12"
subForm1.LinkMasterFields="MasterID11"
subForm1.LinkChildFields="ChildID11"
end select

Unfortunately, this code works inconsistently. It appears that it might
be execution order dependent. In particular, I have had to anticipate an
error that is raised because I change the number of link fields in, say, the
LinkMasterFields property without simultaneously changing it in the
LinkChildFields property (as far as I know, it is not possible to change
these properties simultaneously at runtime). I have worked around this one,
but another is the repositioning, which sometimes works and sometimes
doesn't, and I don't know why.
 
G

Guest

Thanks for the reply

No. Actually, there are 2 discrete problems (can't remember what the other one is, since its been a couple of weeks since I actually switched to my present coding), but the only way I could find to do it was to set my code to ignore errors (On Error Resume Next) and set the SourceObject to nothing, set the link fields, set the SourceObject to the desired string, and set the link fields again

For Example
On Error Resume Nex
subMultiSubform1.SourceObject = "
subMultiSubform1.LinkMasterFields = "mFDEPFacilityID
subMultiSubform1.LinkChildFields = "FDEPFacilityID
subMultiSubform1.SourceObject = "frmResponsibilityHistorySubform
subMultiSubform1.LinkMasterFields = "mFDEPFacilityID
subMultiSubform1.LinkChildFields = "FDEPFacilityID

However, this DOESN'T address the problem of access apparently IGNORING my .Top, .Left, .Height, and .Width assignments

Thanks again

Pa
 
G

Graham Mandeno

Hi Pat

Sorry - I missed the point that the problem was with positioning/sizing
rather than the link fields.

Do you still have On Error Resume Next when changing those properties? If
so, it's likely an error is occurring which is not being raised.

A common problem with resizing and repositioning controls comes from the
fact that the bottom right corner of the control must always be within the
bounds of the section height and form width. A good tip to ensure this is
if Top is increasing, then set Height first, and vice-versa. Same for Left
and Width.

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

pmcguire said:
Thanks for the reply.

No. Actually, there are 2 discrete problems (can't remember what the
other one is, since its been a couple of weeks since I actually switched to
my present coding), but the only way I could find to do it was to set my
code to ignore errors (On Error Resume Next) and set the SourceObject to
nothing, set the link fields, set the SourceObject to the desired string,
and set the link fields again.
For Example:
On Error Resume Next
subMultiSubform1.SourceObject = ""
subMultiSubform1.LinkMasterFields = "mFDEPFacilityID"
subMultiSubform1.LinkChildFields = "FDEPFacilityID"
subMultiSubform1.SourceObject = "frmResponsibilityHistorySubform"
subMultiSubform1.LinkMasterFields = "mFDEPFacilityID"
subMultiSubform1.LinkChildFields = "FDEPFacilityID"

However, this DOESN'T address the problem of access apparently IGNORING my
..Top, .Left, .Height, and .Width assignments.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top