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

Pass value OnOpen from one form to another

Status
Not open for further replies.
Jan 22, 2001
124
US
Hi

This seems like a simple issue, but I just cannot get it to work. When clicking on a command button to open a form, I want to pass a value from one form, to populate a textbox on the newly opened form, BUT I want that value to be passed BEFORE the OnOpen procedures begin.

Example:
A command button on Form1 is used to open Form2. The data displayed when Form2 opens is dependent on what the passed value is. Well, the problem here is two-fold.

1. The OnOpen events are performed before the value is passed. Which is why I can't use this:

DoCmd.OpenForm "Form2
Forms![Form2]![txtbox] = Me![txtbox]

2. I cannot hard-code the form name that calls Form2 to open, because it is not always the same. Which is why I can't use this for the OnOpen event of Form2:

Forms![Form2]![textbox] = Forms![Form1]![txtbox]
then rest of code
...
...
...

I would appreciate any input. Thanks in advance.
 
cant you place the value text on the button prior to openform ie

Dim value As String
value = Your field name '(should be name of text box that holds field)
DoCmd.OpenForm "Form2
Your field name = value
Your field name .SetFocus

Hope this helps
Hymn
 
Thanks for your response. The problem with that is the OnOpen events for Form2 needs the value PRIOR to beginning those events.
 
Dim value As String
value = Your field name '(should be name of text box that holds field)
prior to the opening of your form2
DoCmd.OpenForm "Form2
Your field name = value
Your field name .SetFocus

Hope this helps
Hymn
 
Have you tried using the OpenArgs property. The following is a command button which opens a new form, passing to it the string "This is Me"
Code:
Private Sub cmdTestIt_Click()

   DoCmd.OpenForm "frmTestIt", , , , , , "This Is Me"
   
End Sub
Make sure you've got the correct number of commas. Then in the Form_Load event, you can assign that value to a control on that form, similar to the following:
Code:
Private Sub Form_Load()

   txtYourTextbox = Me.OpenArgs
   
End Sub

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top