need some more simple VB code for an access form

I have a combo box set up with the standard code in the 'on not found' event to open up another form so the user can fill out that form, and then goes back and requeries the combo box.

I dont like the fact that when the user types in his value in the combo box, he/she has to retype the exact same value for the related field in the new box.  I need it to send the value the user typed to the new text box in the new form.

Who is Participating?
Erick37Connect With a Mentor Commented:
One way:

In the new form:


  Me.Text1.Text = frmMain.Combo1.Text  'where frmMain is the form which opened this form
gillgatesConnect With a Mentor Commented:
Suppose your new form is call form2 and the textbox on the form it textbox2

form2.textbox2.Text = "The Text"
salivalAuthor Commented:
i added the code, and i get an error message when loading the new form telling me 'variable not defined' and it highlights the "frmMain" name in my code
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Replace "frmMain" with the name of your main form, it's set to Form1 by default.
If you can't get that working you could always save it in a global variable and then on form_load of your new form just set the textbox.Text to that variable.
salivalAuthor Commented:
yeah, i changed the name (im not that clueless).  Have no clue why it wouldnt be working.    The original form that is calling the second form is a subform within another form, but i dont think that has anything to do with it.
This will work:

From your calling form:

Form2.Text1.Text = Me.Combo1.Text

where Form2 is the new form to be shown
PrestaulConnect With a Mentor Commented:
You can use the OpenArgs property for this.  This is exactly what it is intended for.

1) Modify your "on not found" event code so that it looks something like:

DoCmd.OpenForm FormName:="FormName", OpenArgs:=ComboBox.Text

2) Put something like the following in your Form_Load event on the second form:

If Not IsNull(Me.OpenArgs) Then TextBox.Text = Me.OpenArgs
salivalAuthor Commented:
sorry guys.  i had to take some time away from it and move onto something else.

the trick is, at least in access 97, it has to be Forms!frmMain.text
You don't have to worry about referencing the form (except to launch it) if you use the OpenArgs method I showed above.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.