Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / July 2007

Tip: Looking for answers? Try searching our database.

Passing calling form as a variable

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ian Chappel - 15 Jul 2007 20:50 GMT
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.
Albert D. Kallal - 15 Jul 2007 21:13 GMT
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

Signature

Albert D. Kallal    (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com

Ian Chappel - 16 Jul 2007 00:18 GMT
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?

> You can simply pickup the name of
> the pervious form in the on-open event. In fact, you can grab the previous
[quoted text clipped - 21 lines]
>
> frmPrevous.someVariblename = some value
Albert D. Kallal - 16 Jul 2007 00:48 GMT
"Ian Chappel" <ichappAThotmailDOTcoDOTuk> wrote in message

> 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...

Signature

Albert D. Kallal    (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com

Ian Chappel - 16 Jul 2007 09:58 GMT
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!!

> "Ian Chappel" <ichappAThotmailDOTcoDOTuk> wrote in message
>
[quoted text clipped - 64 lines]
>
> if you don't need an arrary, then just public var name will work...
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.