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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Putting an instance of a subform on a form 1

Status
Not open for further replies.

JennyPeters

Programmer
Oct 29, 2001
228
US
Hi,

This is tricky!

I have a subform that needs to be repeated on a form 3 times. I can make an instance of this subform:

Dim mySub as New Form_frmShiftData

...but can't make this form appear in any way on the main form. I know I can change sourceobject of a subform object on the main form, but that's just a string name, and not the instance of the subform itself.

Any ideas?

Thanks,

jenny
 
Isn't a continuous subform an option ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks, but no. It's not a subform that can be continous, as it's quite complex.

Instead of creating subform1, subform2, subform3, which are all exactly the same, I want an instance of this subform on the main form three times.

More efficient...

Jenny

 
Creating an instance of the subform is only one part of the equation. Remember, to the mainform, a subform is a control on the form, so you must also add the subform control to the form.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
That's precisely the problem.

I can make an unbound subform control, but there is no way to assign my instance of a subform to that control.

Please tell me I'm wrong ;)

Jenny
 
During design, create the additional unbound subform controls, and set their visible property to false. I'm using Child3 in this example as the subform control that I'm attaching the new instance of the ShiftData subform.
Code:
Dim mySub as Form_frmShiftData

Set mySub = New Form_frmShiftData
Child3.SourceObject = mySub.Name
Child3.Form.RecordSource = "Select * ..."
Child3.Form.Requery
Child3.Visible = True


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks CC,

That does work, except for one issue.

If I write a method for the "Form_frmShiftData" like this:

Public Sub changeText()
Me.Text0 = "Jenny"
End Sub

... and call it from the parent form:
mySub.changeText

... it doesn't change the value in the Text0 on the subform...

but...

if you change the method to:
Public Sub changeText()
Me.Text0 = "Jenny"
me.visible = true
End Sub

... the 'mySub' form instance pops up as an independent form on the screen, with the text value changed.

It appears that the instance of the subform was never associated with child3...

Again, please tell me I'm wrong!

Thanks,

Jenny


 
In which code module are you placing the Public Sub changeText() routine?


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
It's a method of the 'mySub' form instance, so the code module in Form_frmShiftData (of which 'mySub' is an instance of')

Jenny

 
How did you add a method to a run-time created instance of a form object?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
That's not the right question, the question should read, how are you calling, from the parent form, the correct instance of mySub.changeText. The call should be in the format

[SubFormControlName].Form.<MethodName>

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I'm actaully calling it from my parent form, in a click event with the following code:

Private Sub cmdAlterText_Click()
Call mySub.changeText
End Sub

If I use mySub.Form.changeText, I get an error that states:
'Application-defined or object-defined error'

p.s. Thanks so much for your help so far.

Jenny
 
Wait, you're right... with a change.

I had to remove the 'Form' from your suggestion of:

'[SubFormControlName].Form.<MethodName> '

to

'[SubFormControlName].<MethodName> '

and use the original form name as the [SubFormControlName], resulting in the final statement of:

Call Form_frmShiftData.changeText

... and it works!


Thanks CC. Couldn't have done it with you!

Jenny

 
I'm glad Jenny that you were able to get it to work.

It's pleasing to know that you use Tek-Tips as much as you do, but I must say, that I was shocked to see that after having asked over 90 questions, that you've yet to indicated that you've found any post helpful. I'm sure that your fellow IT professionals, especially when search for answers, would appreciate knowing those threads in which helpful posts appear. It would help them considerable in finding answers to their own questions. I also hope that as you can, you return the favor by trying to help others in keeping with the give and take spirit of the site.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
CC,

You're right, and I've received a lot of great advice, and have given a little too.

I usually don't mark helpful posts as most of my questions seem to take many posts to reach an answer, but regardless, you're right. I marked your previous post, as it was the 'definitive post' of my problem solved! I'll make a point to do that from now on!

Thanks CC,

Jenny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top