"Instance" of a form as a subform

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 23:52
Joined
Jul 9, 2003
Messages
16,893
I am "playing" with the attached db. It has four forms, frmI, frmII, frmIII and frmIV all practically identical. These forms are used as subforms on a main form "frmTimeManagmentMatrix".

What I would really like to do is just have one form say "frmI" and then have suitably modified "instances" of it instead of the other three subforms. I don't know why I want it, and I don't know why its annoying the hell out of me because I can't make it work :(
So if you know why I can’t load an “Instance” of a form as a subform, or if you know how to load it I would really appreciate some help…

Please note: I had to make the db a mde to get it small enough to load up. If you want a mdb copy I can email it to you.
 

Attachments

I would suggest the you change the SourceObject of the subform using code. This way you can select which subform you want to show...

hth,
Jack
 
The on open event of the form does it:::

Code:
Private Sub Form_Open(Cancel As Integer)

Let Me.subUrgentUrgent.SourceObject = "frmI"
Let Me.subNotUrgentImportant.SourceObject = "frmII"
Let Me.subUrgentNotImportant.SourceObject = "frmIII"
Let Me.subNotUrgentNotImportant.SourceObject = "frmIV"
Let Me.Caption = "                                    " & conAppName

End Sub

But the above is what "Normal" people are happy with, I'm not, I want to open up an "Instance" of the form, in fact I want to open THREE instances of it, change them slightly with the "with Events" do-dah and then display them as subforms... I know Sick ain't I, why can't I be happy with it like it is boo hoo....

No, a grown man should'nt cry, well maybe Tony Blair should be allowed to... lol (Now I'm laughing at my own jokes :(

I have tried the following (This isn't the actual code, I've slung this together by way of an example)

But I can't make it work and I've tried EVERY concevable way of putting the syntax together :( :( (do you have a cry baby smilly?)

Code:
Private Sub Form_Open(Cancel As Integer)

Static frmInstance1 As Form_frmI
Set frmInstance1 = New Form_frmI

With frmOrders
  .Visible = True
  .Detail.BackColor = vbWhite
End With

Let Me.subUrgentUrgent.SourceObject = frmInstance1
Let Me.subNotUrgentImportant.SourceObject = "frmII"
Let Me.subUrgentNotImportant.SourceObject = "frmIII"
Let Me.subNotUrgentNotImportant.SourceObject = "frmIV"
Let Me.Caption = "                                    " & conAppName
 
I just thought of something that might be relevant, could just as easily be the wrong tree though.

When I added the calendar control I had the following problem. I have a function in the calendar form that check to see if the form is open “If IsOpen(stDocName) = True Then"

Well although the main form "frmTimeManagmentMatrix" was open and it had the 4 subforms on it frmI, frmII etc the "Is Open" function was checking to see if the subform "frmI" was open, but it returned "False" it was as if, because it was a subform it Wasn't open in its own right.

Ahh !!! A moment of inspiration... Maybe I have to use the full path (What’s the correct term, I know this ain't) something like:

Me!Subform1.Form.RecordSource

Where Subform1 is the sub form control...

I think I got it!!! :) :)

If I have I'll let you know, if not Well...

(Edited because I Forgot to Spell check)
 
Last edited:
No :( it was the wrong tree, this only works with an existing form, can't change the form "Instance" with it.

Code:
'Me!Subform1.Form.RecordSource

Code:
Private Sub Form_Open(Cancel As Integer)
Static frmStat1 As Form_frmI
Set frmStat1 = New Form_frmI
   
With frmStat1
  .Visible = True
  .Detail.BackColor = vbWhite
End With

Let Me.subUrgentUrgent.SourceObject = frmStat1
Let Me.subNotUrgentImportant.SourceObject = "frmII"
Let Me.subUrgentNotImportant.SourceObject = "frmIII"
Let Me.subNotUrgentNotImportant.SourceObject = "frmIV"
Let Me.Caption = "                                    " & conAppName

End Sub
 
I am not aware of any way to open 4 'instances' of a single form, modify them and then place them in subforms. I understand your desire to 'go where no man has gone before' but is it worth it? Other than personal satisfaction I don't see any programming advantage to doing this.

As for a subform showing as being loaded, you can't because a subform is just another control on a form. Only one form can have the focus at a time, in Access, so either a form 'IsLoaded' or it is not.

I do not want to slow you down in your quest, but at this point I have no expertise that I can share with you. I do wish you good luck in this quest and I think it unlikely that the PM will weep...

Jack
 
Right, well I got the idea from an article by Garry Robinson called Microsoft Access - Forms All Class published in Smart Access. You can see the article and down load the code from their site...

Correction:
The catch is you need to setup a trial subscription.

There is now a free version of Garry Robinson's article see a later response.

Main benefits
Gary Says:

"The primary reason I've been manipulating the properties of forms in code is to set up different styles of interfaces for my end users without generating multiple copies of what's basically the same form"

And I say:
Since I started using the form as an object found that I don't need to use "open Args" any more, they can be clumsy to say the least. I only need to make one basic form, which I can then use for Viewing, data entry etc. The main benefit here is if you make a "change to your db, for example you add another field then you only need to modify one form, all the "instances" of it are modified as well because its essentially the same form. I haven't actually used two "instances" together yet as described by Gary, but I'm sure there will come a time when it’s necessary. In fact I'd like to use this method on the db attached earlier in this thread.
 
Last edited:
Surely that only works with data from one table, the point of subforms is to display child related records/fields
 
>>>the point of subforms is to display child related records/fields<<<<

That’s a good point, it’s not necessary to have the same subform twice or more… But hold on, it is in this situation for example, in the db attached, if I added a field to the main form showing today’s date, then each subform could show a list of today’s tasks unique to that subform. Back to square one.
 
You web site looks fine! My question is about the Time Matrix database... No matter which 'square' I enter data into it always shows up in the upper left 'Urgent' part of the form? Just curious...

Jack
 
>>>>No matter which 'square' I enter data into it always shows up in the upper left<<<<

It shouldn't do that! I'll have a look and get back to you...
 
Well before I posted it i checked it and it worked ok, honest... I found the problem and corrected it, it shouldn't happen again. If theres any thing else wrong please let me know.
 
A Solution....

Jack.... Re: >>>unlikely that the PM will weep... <<<<

Did I hear right? Tony Blair was weeping a little bit the other day?

And after revisiting this problem just this week, I think I have a working solution.

I'm a little bit hesitant because it seemed so simple when I went back to it. There must be something important I have forgotten!

Please see attached file:
 

Attachments

Last edited:
Hmm.

Looks like someone already thought of this bright idea I had of creating my own collection of controls in a unbound form to be dropped in subform.

Based from what I see, creating an instance is very weird- it's not in Forms collection, and for all purpose, it's nonexistent to Access. Therefore, I cannot attach the created instance to a subform because Access wants to look up the Forms or AllForm collection, either which are read-only.

I wonder if there is a way to override the read-only limitation- by editing the system tables? :eek:

I also mused about creating a copyobject, but that still requires a form within the collection. I simply do not get Access's arbitrary limitation on what I can do with forms and the instances.

If this could be overcome, this would make everything so easy. Cascading combobox? Drag'n'drop a subform, set some properties and move on! No more monkeying with individual After_Update event. Need more functionality? Edit the master and the changes propagate all over the places! No more silly errors because you forgot to set an AfterUpdate event or something stupid like that.

The idea I was kicking around, given the present limitation, is to do this way:

1) Create a generic form- In this example, we just put in two combobox and give it the necessary code to make it cascading. Add some public properties to set the rowsource and bind the control source to parent's recordsource.

2) Drop it as necessary.

3) Use a module, with a constant boolean which is manually turned on or off to create a copy of the master form, and individualize it for a particular form, save it with a different name then update the subform's sourceobject. In all case, it will have to have something that can be easily updated (e.g. tagging it with the name of master form)

4) Whenever we edit a database, the code will run everytime we make changes to the form/subform (deleting the old copy, creating a new copy from the master copy) so everything stays up to the date. The Open event for the parent form will fire the code for its associated form. (Maybe this can be somewhere else...)

5) When it is ready for production, turn the boolean off and distribute it. The subforms are no longer updated, so it loads faster for the end user.

I'm debating whether this setup would be ultimately time-saving once set up, or will it just be a half-assed mockery of object-oriented programming?
 

Users who are viewing this thread

Back
Top Bottom