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!

Remembering which form opens another one.

Status
Not open for further replies.

Ma3x323

Programmer
Jun 27, 2001
148
US
Hi peeps,
Is there a way that when you open a form, the opened form will know which form opened it?
I am trying to make a form in which the data in it depends on the form that opens it. I would like to know the code and where to put it in.

Thanks,
Feryl
 
Let's say you have Form1 and Form2 and you want to open Form3 so that it knows which form opened it. Let's assume you are using a command button, cmdOpenForm, to open the form.

1. In the OnClick event of cmdOpenForm, type:

Code:
docmd.OpenForm, "Form3",,,,,,"Form1"

Do the same for the button's event handler in Form2 but change the bit at the end of the line to "Form2". This is the OpenArgs parameter of the OpenForm action.

In Form3 you can refer to Me.OpenArgs and it will return the name of the form that opened it. Have fun! :eek:)

Alex Middleton
 
Thanks. . . I got it to work.

Now, I am trying to get a value from Form1 so Form3 can use it. How do I do that?
Obviously, doing Forms![Me.OpenArgs] would not work because that would be a string. Anyway to do this?

-Feryl :p
 
Nevermind, I figured it out. I passed the value needed as an OpenArg.
But I am curious as to the possibility that I can pass more than one value to OpenArgs in case I need more values?

-F-Dawg X-)
 
You can use the form index to reference the form and control. Paste this function into a module to get the form index:

[tt]
Function FindFormIndex(FormName As String) As Integer
Dim i As Integer

'Use For to find form index
For i = 0 To (Forms.Count - 1)
If Forms(i).Name = FormName Then
FindFormIndex = i
Exit Function
End If
Next i

'Return -1 if form is not loaded
FindFormIndex = -1
End Function
[/tt]

Now in your code do this:

[tt]
Dim i As Integer
i = FindFormIndex(Me.OpenArgs)

'Now execute your code, referring to form like this
Forms(i).MyControlName = YadaYadaYada
[tt]

HTH

Joe Miller
joe.miller@flotech.net
 
You gave OVERKILL a new meaning Joe. But that's alright. It works nice and dandy.
Now I have a new situation. . .
Ok Form3 has options in it (buttons on mine) and if you click an option, Form3 will close. How do I put that option (a String on my case) into a table I made (a new data)?

If confused, don't hesitate to ask. I will be on the lookout for the next 6 hours. s-)

-Feryl
 
I suggest you start a new thread and explain a little better. I have no idea what you're talking about, sorry.

Joe Joe Miller
joe.miller@flotech.net
 
Well. . . here it goes.
I am trying to make an order menu where the table contains several food and the prices, etc. I also have a form for this. Since sometimes there are 2 prices for a specific item, I made the form (Form1) pop up Form3 which has buttons for choosing which price the customer wants. When a button is pressed, I want the price, the item #, the food name and all that good stuff go to a different table (tblOrders). Now how do I do that?

I hope this would kinda make sense.
:-V
F-Dawg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top