Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

need some more simple VB code for an access form

Posted on 2004-09-22
10
Medium Priority
?
135 Views
Last Modified: 2010-05-02
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
Comment
Question by:salival
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 3

Assisted Solution

by:gillgates
gillgates earned 664 total points
ID: 12124608
Suppose your new form is call form2 and the textbox on the form it textbox2

form2.textbox2.SetFocus
form2.textbox2.Text = "The Text"
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 668 total points
ID: 12124609
One way:

In the new form:

Form_Load

  Me.Text1.Text = frmMain.Combo1.Text  'where frmMain is the form which opened this form
0
 

Author Comment

by:salival
ID: 12125349
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Expert Comment

by:Erick37
ID: 12125366
Replace "frmMain" with the name of your main form, it's set to Form1 by default.
0
 
LVL 3

Expert Comment

by:gillgates
ID: 12125400
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
 

Author Comment

by:salival
ID: 12125467
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
 
LVL 32

Expert Comment

by:Erick37
ID: 12125572
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
 
LVL 4

Assisted Solution

by:Prestaul
Prestaul earned 668 total points
ID: 12126939
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
 

Author Comment

by:salival
ID: 12136437
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
 
LVL 4

Expert Comment

by:Prestaul
ID: 12136460
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question