Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 136
  • Last Modified:

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.

Thanks.
0
salival
Asked:
salival
  • 3
  • 3
  • 2
  • +1
3 Solutions
 
gillgatesCommented:
Suppose your new form is call form2 and the textbox on the form it textbox2

form2.textbox2.SetFocus
form2.textbox2.Text = "The Text"
0
 
Erick37Commented:
One way:

In the new form:

Form_Load

  Me.Text1.Text = frmMain.Combo1.Text  'where frmMain is the form which opened this form
0
 
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
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Erick37Commented:
Replace "frmMain" with the name of your main form, it's set to Form1 by default.
0
 
gillgatesCommented:
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.
0
 
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.
0
 
Erick37Commented:
This will work:

From your calling form:

Form2.Text1.Text = Me.Combo1.Text
Form2.Show


where Form2 is the new form to be shown
0
 
PrestaulCommented:
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
0
 
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
0
 
PrestaulCommented:
You don't have to worry about referencing the form (except to launch it) if you use the OpenArgs method I showed above.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now