Passing calling form as a variable

I

Ian Chappel

I double-click a control to bring up a small modal/popup Search Form. I need
to pass a value generated in the Search Form back to the initiating form (in
fact the control I double-clicked), when I close the Search Form.

How do I get the Search Form to know which form has called it? I think I can
use ActiveControl for the control.

Thanks.
 
A

Albert D. Kallal

You can simply pickup the name of
the pervious form in the on-open event. In fact, you can grab the previous
form name as late as the on-load even. Hence, the following works well


Option Explicit
dim frmPrevious as form


Then, in the on-open.


set frmPrevious = screen.ActiveForm


Now, anywhere in code, you can use fields, properties and even code of the
previous from


msgbox "calling form = " & frmPrevious.Name


frmPrevious!LastName = "bla bla bla"


frmPrevious.Refresh


Or, even call custom code or methods from that previous form like:


frmPrevous.MyRefresh

frmPrevous.someVariblename = some value
 
I

Ian Chappel

Thanks Albert, that's great.

I am however having trouble setting a variable's value in the calling form.
The variable is declared right after Option Explicit in the calling form,
and is a one-dimensional string array. Maybe I need to make the variable
Public, but I get an error when I do so. Or should I use a simple public
string variable - if so, what event could I use to assign it's value to the
array element?
 
A

Albert D. Kallal

Ian Chappel said:
I am however having trouble setting a variable's value in the calling
form. The variable is declared right after Option Explicit in the calling
form, and is a one-dimensional string array. Maybe I need to make the
variable Public, but I get an error when I do so. Or should I use a simple
public string variable - if so, what event could I use to assign it's
value to the array element?

yes, I did not realize the above. Ok, if you go

public Mystring as string

The above works.

And:

dim MyString(5) as string

The above works

however, public, such as:

Public MyString(5) as string

The above is NOT allowed. I did not know this (but hey that way I spend time
here in these newsgroups to learn!).

however, you can get around this:

You can simply build a set of custom property "gets" and "lets" for a form.
Remember, any pubic function of a forms module becomes a method, and also
that let/get are legal. The form is a basic class object.

So, just go:

Option Compare Database
Option Explicit

Dim buf(10) As String

Public Property Get Nbuf(i As Integer) As String

Nbuf = buf(i)

End Property

Public Property Let Nbuf(i As Integer, s As String)

buf(i) = s

End Property


The above will simply expose a public property called NBuf that lets I
get/let the value of buf().

So, then, you can go:


forms("myform").NBuf(1) = "abc"

or

debug.print forms("myform").NBuf(1)
--> abc

So, you can reference the array through a public property get/let....

if you don't need an arrary, then just public var name will work...
 
I

Ian Chappel

Thanks Albert, all sorted.

Used a Public string, then set the string array element to the string's
value. Glad you've learnt something as well!!
 

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