Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switching Subform Sources at Runtime

Status
Not open for further replies.

ESquared

Programmer
Dec 23, 2003
6,129
US
I just now read in the help that you cannot modify the LinkChildFields and LinkMasterFields properties at runtime. It actually looks like it would let you, if only you could change them both at once. (The error I got was about changing the number of linked fields.)

Now that I know this, I'm a bit frustrated because my table design nearly requires this method. I hope you'll bear with me and let me explain:

I have a table called Entities. Everything goes in here: users, customers, the System (my company), vendors.

Each entity record has as many fields as are common to each kind of entity, such as DisplayName, DateCreated, Enabled, and that sort of thing.

Each different kind of entity has its own table with its custom information: Login name and password for users, customer addresses, etc. You get the idea.

The reason I designed the database this way is because
1) my forms have several places where they need to capture a value that could be a different kind of entity. For example, an issue can be assigned to a specific user in my company but could also be assigned to one of our vendors. There are others similar to this.
2) I can specify an owner for each entity and end up with a hierarchical tree: these users belong to this company, but these other users belong to this other company. (This is a valid scenario, we hire 3rd-party companies to do programming and they could conceivably need access as users.)
3) This database structure is very tolerant of new additions and new kinds of entity types when compared to other methods I could envision. For example, all the forms which do a lookup to the entities table will automatically see the new kind without a single code change. Changes that are required are more likely to be in the queries and form/listbox/combobox sources to include or exclude the new type, but how quick a change is that?

My main data entry forms are working great because for the most part one simply selects the entity one wants from the entities table. Forms that deal with a specific kind of entity pull from the specific table.

However, now I am working on the "entity maintenance" forms. I have an unbound listbox with all entities in it. Later I will add options to sort and filter this box. In the meantime, when an item is selected, I had planned to switch the subform to the correct form which contains all the data entry controls specific to that kind of entity.

It is actually working for 3 of my 4 kinds of entities, except that I'm running into a problem with Access's oh-so-wonderful auto-link feature. (This is Access 97, and no I can't use 2000 right now.) Even though I set the LinkMasterFields and LinkChildFields properties correctly at design-time (and the link field names are uniform across all my tables, "EntityID" for master and "Entity" for Child), when I change the SourceObject property at runtime, Access butts in and changes these based on the relationships in my database. They are fairly complex and I end up with incorrect values for linking. Maybe I can prune these to end up with what I want, but what I'd rather have is to stop Access 97 from automatically (and incorrectly) filling in these properties. Can I do this? Should I bother trying deleting the relationships entirely to see if Access then leaves well enough alone?

Should I put a subform for each entity type on my form, and simply hide the incorrect ones?

Should I make four separate forms to edit all the data about an entity, including the common data that sits in my Entities table, one for each entity type? So much for going to one place to see all entities.

Did I make a mistake in my fundamental database design to begin with?

Anyone? Anyone? :)

-E²
 
I should add: I am doing the presto-change-o in the forms OnCurrent Event. Should I do it in listboxes OnUpdate event, where I am changing records with RecordsetClone.FindFirst?

Also, could I also change the subform's record manually? How do I make Access let me do this?
 
I'd have answered your question if you hadn't bumped it.

I'm sure someone will, though. Just be a little more patient. You included a LOT of information for people to read through, so it's going to take a very patient person to give you an answer.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
You mean that you deliberately aren't answering because I did bump it? Am I to take it that a bump is considered ill-mannered? And now I'm being punished?

I certainly would have not done it if I'd read in any FAQ that it was frowned upon (and yes, I've read the etiquette FAQ and other guideline FAQs).

For what it's worth, I bumped it because I spent about 2 hours answering other people's questions in this forum... more than 15 different threads. I felt I'd "earned it."

 
Should I bother trying deleting the relationships entirely to see if Access then leaves well enough alone?

Should I put a subform for each entity type on my form, and simply hide the incorrect ones?

--
These are the two things I would suggest you try first. Or, a variation of the second, a tab control with one for each entity type.

There's a way to have the little tab at the top not show. Just make it so you can see them when you're designing the form, to make it easier to switch between them, and then when you're going to put the form into production, hide them. Be sure to do some testing because my memory is that there is some shift in the space available to you for placing controls when you make this change.

One advantage to using a tab control over multiple subforms is that all of the code will be in the same form, so you'll be able to use the Me keyword, and have a few other luxuries at hand.

Do you get an error if you set one of the link fields to null (or "")? I would assume so, but it might be worth a test.

Jeremy

PS: There are a lot of posts on these fora, and lots of them scream out their subjects in ALL CAPS, or use a bunch of *** at the start and end, or use words like "urgent". I do my best to avoid answering all of these posts. I generally don't answer bumped posts, either. Everyone's question is important to the asker, or people wouldn't bother asking.

Also, I think it's dangerous to think you've _ever_ earned an answer here. No one gets paid to answer these questions. People answer questions because it's fun and it feels good. If it happens not to feel good to anyone to answer your question, that's just the way it is. No one owes anyone anything here. There's a big exchange of ideas, and most people here get decent answers to their questions. But some questions fade away with no answers at all. That's just the way it is. I do think it's great that you're answering questions for other people. Hopefully you're getting something out of the process. But I wouldn't advise seeing that as having earned you anything.

[I want to be clear that I'm not being sarcastic or snide. You may not like what I'm saying, but I assure you that I'm not swiping at you, just giving you my (possibly paternalistic) advice.]

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
This project went on hold today because of other things that took higher priority... I'll try what I can as soon as possible and post the results here.

Thanks for the response.

-E²


P.S. I understand that I am not *entitled* to anyone's time, effort, and help. That's most certainly not what I meant about offering my help to other people. In fact, I have my own annoyance issues when exposed to misplaced entitlement. You see, I didn't feel I'd earned an *answer*, just a bump. Since I had moved my own post 14 or 15 down the list, I put it back at the top: it was about visibility and nothing more.

I in fact try to save people time and effort by giving them all the information in one shot, instead of doing like in many threads where contributors must milk the questioner for information multiple times before truly being able to help.

For what it's worth, I do think your reaction was out of proportion: seemingly immediately ascribing to me incorrect motives and thoughts ("he feels entitled to my help"). To throw out some 2-bit psychology, is there some extra sensitivity present about being unappreciated or invalidated? To even mention asterisks and all caps when they are not present suggests to me I got automatically lumped in a broad mental category, one that pushes your buttons.

Heh. Remember... 2-bit.

Perhaps 2-bit psychology might also suggest that my lengthy and pedantic response indicates something got under *my* skin, too.
 
<G>

EE, all points heard. Let's keep it where it's at, recognize the relatively small importance of all of this, and keep things friendly.

And do our best not to keep _this_ thread at the top of the list for too long, else people are likely to think we're both in need of some serious help!

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
I get prickly sometimes at the darnedest things. Sometimes I feel I just can't help it. Room to grow, I suppose.
 
Still interessted?

"I just now read in the help that you cannot modify the LinkChildFields and LinkMasterFields properties at runtime."

That's not the truth.
The linked-fields can be accesed with read and write operations. So first null and then change 'em.

P.S. What is "bump"? Never read it before..
 
How are ya JeremyNYC . . . . .

Instead of getting bent about certain kinds of posts . . . . . [blue]why not enjoy your life more instead![/blue] ;-)

Calvin.gif
See Ya! . . . . . .
 
Joker007,

Thanks for the info. I'll keep it in mind in the future. Bump means to make a thread show up at the top of the list by posting a message in it that may or may not have any important content in it.

TheAceman1,

That silly argument was 11 months ago. Why comment on it now?
 
ESquared . . . . .

Ya know . . . . . I didn't pay attention to the dates!

Calvin.gif
See Ya! . . . . . .
 
Heh. Kind of funny that this got re-bumped.

I've actually dealt with setting link fields at run-time recently. I don't know if this is the crux of the issue you were facing a year ago, or if this was just a sidelight. I assume you've found _some_ workaround by now (I hope so, for the sake of your frustration level), but if not, or just for the heck of it, here's how we dealt with it (the key is in the error handler portion of the code, at the bottom):
Code:
Private Sub tabDescription_Change()
On Error GoTo Error
Dim strType As String

Call Application.Echo(False)
Select Case Me!tabDescription
Case 0
    strType = "Role"
Case 1
    strType = "Task"
Case 2
    strType = "Action"
Case 3
    strType = "Step"
End Select

With Me!frmDescription
    .Form!txtID.ControlSource = strType & "ID"
    .Form!txtDescription.ControlSource = strType & "Description"
    .Form!txtDiscussion.ControlSource = strType & "Discussion"
    .Form!txtBusinessrules.ControlSource = strType & "BusinessRules"
    .LinkChildFields = ""
    .LinkMasterFields = ""
    .Form.RecordSource = "SELECT " & strType & "ID, " & strType & "Description, " & strType & "Discussion, " _
     & strType & "BusinessRules " _
     & "FROM tbl" & strType
    .LinkChildFields = strType & "ID"
    If strType = "Action" Then
        .LinkMasterFields = "txtLeft" & strType & "ID"
    Else
        .LinkMasterFields = "txt" & strType & "ID"
    End If
End With

ExitPoint:
On Error Resume Next
Call Application.Echo(True)

Exit Sub
Error:
Select Case Err.Number
Case 2335 'Doesn't like setting Link fields in code, but it's alright
    Resume Next
Case Else
    Call ErrorTrap(Err.Number, Err.Description, "tabDescription_Change")
End Select
GoTo ExitPoint

End Sub

Joker, do I avoid the error if I set to null instead of ""?

Jeremy

PS: AceMan: doing well, loving my new full-time gig, and learning a ton. metrix.fcny.org, if you're interested in where I'm at. How are you?

---
Jeremy Wallace
METRIX Project Coordinator
Fund for the City of New York
 
Interesting.

I will try to remember the principle for the future rather than the exact situation (which I may never run into again).

The principles I see are:

- If something doesn't allow you to change a value, try changing the value to an empty string or a null, first.

- If an error occurs, this doesn't necessarily mean that the action failed. See what happens when you resume execution after the error.

The principles can apply to any situation.
 
Hi JeremyNYC,

I'll soon rollout a new software, using the following code.
I never had a problem with it. Please let me know if it works for you..

With sfrmDetail
If .LinkMasterFields <> "" Then .LinkMasterFields = "" 'disbale old links and subfrom
If .LinkChildFields <> "" Then .LinkChildFields = ""
.SourceObject = ""
DoEvents
.SourceObject = "frmNew" 'define new source form and links
If CurrSetting.strViewFieldMaster <> "" Then .LinkMasterFields = "fldMaster"
If CurrSetting.strFrmFieldDetail <> "" Then .LinkChildFields = "fldDetail"
End With



It's allways import to set the fields first and after that the source object.
It's also a good choice to set the echo off, the way you did.
 
Hi JeremyNYC,

I'll soon rollout a new software, using the following code.
I never had a problem with it. Please let me know if it works for you..

With sfrmDetail
If .LinkMasterFields <> "" Then .LinkMasterFields = "" 'disbale old links and subfrom
If .LinkChildFields <> "" Then .LinkChildFields = ""
.SourceObject = ""
DoEvents
.SourceObject = "frmNew" 'define new source form and links
If CurrSetting.strViewFieldMaster <> "" Then .LinkMasterFields = "fldMaster"
If CurrSetting.strFrmFieldDetail <> "" Then .LinkChildFields = "fldDetail"
End With



It's allways importent to set the fields first and after that the source object.
It's also a good choice to set the echo off, the way you did.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top