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

Accessing a variables value in Forms.variable 2

Status
Not open for further replies.

TheFitz

Programmer
Dec 18, 2003
140
GB
Hi all,

This is a really easy one, but for some reason Google can't help me!! I know it's possible as I've done it before, but I can't remember the code.

When the form is called from it's calling form, the calling form passes it's name in OpenArgs.

I am trying to get the process to call the function "ReturnedStudentID" on the parent form. The code works if I add in the form name directly, however, this child form will be called from a variety of places and I want to add the OpenArgs value to the Forms. command.

I know all I am missing is the value of xxxx which is a function. For some reason I thought is was Param, but I think that's a different language.

Here's what i've got so far:

Code:
Call Forms.xxxx(Me.OpenArgs).ReturnedStudentID(Me.ComboSelectStudent)

Any help in finding this would be appreciated, but I jsut can't remember the syntax.

A star for the first person to remind me of the command!!

Many thanks in advance,

Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
 
How are ya TheFitz . . .

[ol][li]1st make sure the function is Public:
Code:
[blue]Public Function ReturnedStudentID()[/blue]
[/li]
[li]Then in the [blue]called form[/blue] try the following:
Code:
[blue]   Dim ID

   ID = Forms([purple][b]Me.OpenArgs[/b][/purple]).ReturnedStudentID[/blue]
[/li][/ol]

[blue]Your Thoughts? . . .[/blue]



See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Call Forms(Me.OpenArgs).ReturnedStudentID(Me.ComboSelectStudent)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks both, exactly what I needed. I knew it was simple and I was doing something really silly.

All working fine. Thanks, have a star each!!! ;-)


Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
 
If I understand this, it just seems a little strange and overly complicated.

You have a multiple calling forms that can call a form. These multiple calling forms all have a function "returnedStudentID". The called form uses open args to figure out which form called it, and runs the "returnedStudentID" function on the form that called it.

There has to be a better design then that. Could you put ReturnedStudentID in a standardModule, and if necessary you would pass to the function the calling form and the value.

public returnedStudentID(callingFrm as access.form, calledStudent as variant) as long
 
Hi MajP

That's true, it is overly complicated given the information that I've given to you, however, when the 'child' form returns focus to the 'parent'/calling form, I need a specific sub routine to run on the 'parent' form.

In short, return the value to the parent form and then do something specific to that form on that form.

Good thoughts tho,

Thanks,

Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
 
Is the child form open in dialog? There may be a cleaner simpler way to do that. If interested provide some details of how the forms work together.
 
My suggestion is too have the calling form always maintain program flow.

2 ways.
1) The called form is open in dialog
In this case the program flow stops in the calling form until the called form is either closed or hidden.
So Assume I have a pop up form that many forms call to get some value. For example the called form has a combobox "cmboID". On the called form I put two buttons, "OK" and "Cancel"
"OK" makes the pop up invisible
"Cancel" closes the form

So in the calling form I have some procedure that needs a value from the popup.

...some code
'Pop open the dialog form
dim studentID as long
Docmd.openform "frmPopUp", acNormal, , , , acDialog
'Code stops here until popup closed
'When code returns check to see if the pop up is open but hidden. User selected OK.
if currentproject.allforms("frmPopUp").isloaded then
studentID = forms("frmPopUp").cmboID
docmd.close acform,"frmPopUp"
'run some code
else
'So the user cancelled out of the pop up
'Do nothing or do something here
end if


Now, if I often use the pop up to get a value you can wrap the above in a function
Code:
public function getStudentID() as long
  Docmd.openform "frmPopUp", acNormal, , , , acDialog
  'Code stops here until popup closed
  'When code returns check to see if the pop up is open but hidden. User selected OK.
  if currentproject.allforms("frmPopUp").isloaded then
     getStudentID = forms("frmPopUp").cmboID
     docmd.close acform,"frmPopUp"
  end if
end function

so now from the calling form
if getStudentID <> 0 then
'code stops until frmPopUp closes/hidden
end if

2) If the called form is not dialog then code execution does not stop. But you can capture the called forms events or the event of any control on the form. I capture the combos event, but I could capture any controls event.

From the calling form
Code:
Public WithEvents calledCombo As Access.ComboBox
Private Sub calledCombo_AfterUpdate()
  'Capture the after update event of a control on
  'the other form.
  Me.txtBxOne = calledCombo
End Sub
Private Sub cmdOpen_Click()
  DoCmd.OpenForm "frmCalled"
  Set calledCombo = Forms("frmCalled").cmboCalled
  calledCombo.AfterUpdate = "[Event Procedure]"
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top