By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,490 Members | 1,712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,490 IT Pros & Developers. It's quick & easy.

Fill textbox onClick from another Form

P: 4
Hi all,

I've got a form1 that has 6 check boxes that are named A-F. They all open the same form2 when clicked on. form2 has three text boxes and I'd like it so that one of them contains the name of the checkbox from the previous form.

I'm having trouble writing the VBA for this and there might be an easier way all together that I just don't know about. I'm very new to Access and have little experience with VBA at this point so go ahead and point me in a different direction if you see one.

Thanks in advance.
Feb 1 '08 #1
Share this Question
Share on Google+
5 Replies


MindBender77
100+
P: 234
Hi all,

I've got a form1 that has 6 check boxes that are named A-F. They all open the same form2 when clicked on. form2 has three text boxes and I'd like it so that one of them contains the name of the checkbox from the previous form.

Thanks in advance.
You can make the control source for the textbox from the properties menu:
Expand|Select|Wrap|Line Numbers
  1. =[Forms]![Form1]![YourCheckBoxLabel].Caption
  2.  
However, if you 6 checkboxes and they all open the same form with only 3 textboxes, this might cause problems later on.

Hope this Helps,
JS
Feb 1 '08 #2

P: 4
Ok, that works, but like you said, it only works for whatever checkbox name I have in there.

In VBA would I be able to write something like
Expand|Select|Wrap|Line Numbers
  1. Dim cb As CheckBox
  2. Dim txt As TextBox
  3. Dim i As Integer
  4.  
  5. Set cb = [I don't know what would go here]
  6. Set txt = " "
  7.  
I think I could figure it out from there, but I'm not sure how to make sure that the text box is the one I want as well as the checkbox.

Any thoughts?
Feb 1 '08 #3

MindBender77
100+
P: 234
Ok, that works, but like you said, it only works for whatever checkbox name I have in there.

I think I could figure it out from there, but I'm not sure how to make sure that the text box is the one I want as well as the checkbox.

Any thoughts?

On the OnOpen event of Form2 you could do something like this:
Expand|Select|Wrap|Line Numbers
  1. If [Forms]![Form1]![Checkbox1].Value = -1 Then 'Checked
  2. Textbox1 = [Forms]![Form1]![Checkbox1].Caption
  3. End If
  4.  
  5. If [Forms]![Form1]![Checkbox2].Value = -1 Then 'Checked
  6. Textbox1 = [Forms]![Form1]![Checkbox2].Caption
  7. End If
  8.  
Note this does work, however, I believe there are easier ways to do this.

JS
Feb 1 '08 #4

P: 4
On the OnOpen event of Form2 you could do something like this:
Expand|Select|Wrap|Line Numbers
  1. If [Forms]![Form1]![Checkbox1].Value = -1 Then 'Checked
  2. Textbox1 = [Forms]![Form1]![Checkbox1].Caption
  3. End If
  4.  
  5. If [Forms]![Form1]![Checkbox2].Value = -1 Then 'Checked
  6. Textbox1 = [Forms]![Form1]![Checkbox2].Caption
  7. End If
  8.  
Note this does work, however, I believe there are easier ways to do this.

JS

Ok, so now for a question that I should know the answer to.

How should I define Textbox1?

Expand|Select|Wrap|Line Numbers
  1. Dim tb As Textbox
  2. Set tb  = ???
On the right track? I don't know how to make it know that I want the name to go into the specific textbox.
Feb 1 '08 #5

MindBender77
100+
P: 234
Ok, so now for a question that I should know the answer to.

How should I define Textbox1?

Expand|Select|Wrap|Line Numbers
  1. Dim tb As Textbox
  2. Set tb  = ???
On the right track? I don't know how to make it know that I want the name to go into the specific textbox.
As a personal preference, I don't use ie. (Dim X) to define a control. This is do reduce the about of code needed.

Instead, I'd go under the properties menu for each textbox, under the "Other" tab, and Name: Name the textbox something descriptive for that specific control. Ex. Name textbox1 something like txt_orderdata.

So when you refer to it in code it would like:
Expand|Select|Wrap|Line Numbers
  1. txt_orderdata = [Forms]![Form1]![Checkbox2].Caption
  2.  
JS
Feb 1 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.