accessing one form to another form

biazer911
09-30-2001, 07:53 AM
I have one form that has around 100 check boxes that the user can chose from and I would like to collect this information on another form without alot of hassles can anyone aid me in this.

Thank you in advance

Squirm
09-30-2001, 08:09 AM
If you want to access the controls on another form, the you just need to add the form name infront of the control. Thoe following code could be placed in any form or code module:

<pre>Form1.Check1.Value = 1</pre>

Even if this is done from Form2, it will still affect Form1. If you find that you are doing a lot of stuff dealing with the other form, then I would suggest using With:

<pre>With Form1
.Check1.Value = 1
.Check2.Value = 0
.Caption = "Form 1"
.Label1.Caption = "Some text"
.Label2.BackColor = vbRed
End With</pre>

biazer911
09-30-2001, 08:28 AM
so if my code looks like this (showing the results in a text box on the orignal form)

Private Sub Check_2attack_Click()
If Check_2attack.Value = Checked Then
Text1.Text = Text1 + (";2_attack")
End If
End Sub

what would I need to change to have it show the results on the second form

would it be :

with form1
.check_2attack.value = checked
.Text1.Text = Text1 + (";2_attack")
end with

Squirm
09-30-2001, 08:37 AM
If check_2attack and Text1 are objects on Form1, yes. This will not, however, show ANYTHING on form2.

biazer911
09-30-2001, 08:40 AM
so how would I get it to show on form 2

Squirm
09-30-2001, 08:45 AM
Right, lets suppose you have two forms, Form1 and Form2, and you want the value of a textbox to change on Form2 depending on the value of a checkbox on Form1, by clicking a button on Form1. You would add this code to Form1:

<pre>Private Sub Command1_Click()
Form2.Show
End Sub</pre>

And this code in the code window of Form2:

<pre>Private Sub Form_Load()
If Form1.Check1.Value = 1 Then
Text1.Text = "The box on form1 is checked"
Else
Text1.Text = "The box on form1 in unchecked"
End If
End Sub</pre>

This is how you access controls from other forms.

biazer911
09-30-2001, 08:56 AM
thank you kind sir that is exactly what I was looking for

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum