![]() |
![]() |
#1 (permalink) |
Addict
Location: Grey Britain
|
[vb6] referring back to a form
I'm working with some source code where formA loads formB, the formB accesses and modifies a recordset belonging to formA. I've been asked to modify the source in such a way that formB can be loaded from any of forms A, C, D, E or F (all of which are incidences of formAlfa) and refer to whichever form it was loaded from.
I could do it by making a completely different form like formB, for each of these calls, but that seems a bit ass. Any ideas how I can say 'formthatcalledme.data1.recordset', rather than formA.data1.recordset, formB.data1.recordset, etc? Or is there any other way to work round this?
__________________
"No one was behaving from very Buddhist motives. Then, thought Pigsy, he was hardly a Buddha, nor was he a monkey. Presently, he was a pig spirit changed into a little girl pretending to be a little boy to be offered to a water monster. It was all very simple to a pig spirit." |
![]() |
![]() |
#2 (permalink) |
Tilted
|
Two ways: Implements, or late binding. Late binding would probably be easiest. If you cast the Form variables to Object, you can make whatever calls you want to them, and they're not checked at compile time, only at run time, so you can go:
Dim frm As Form Set frm = FormA 'For example Dim o As Object Set o = frm o.Data1.whatever And it'll work, provided that FormA really does have a Data1 property. Implements is perhaps the more correct way of doing things, but much more involved, so I won't go into it 'less you really want. |
![]() |
![]() |
#3 (permalink) |
Addict
Location: Grey Britain
|
Excellent, thanks. I shall use that one next time as I'm expecting to have a similar problem again.
My boss was breathing down my neck on this one, so in the end I bodged it by passing a string to formB which held the name of the form it came from, then making a giant switch.
__________________
"No one was behaving from very Buddhist motives. Then, thought Pigsy, he was hardly a Buddha, nor was he a monkey. Presently, he was a pig spirit changed into a little girl pretending to be a little boy to be offered to a water monster. It was all very simple to a pig spirit." |
![]() |
Tags |
back, form, referring, vb6 |
|
|