Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Link Forms

Status
Not open for further replies.

mobuto

MIS
Aug 26, 2003
13
CA
Can anyone give me advice on how to link controls in a form. I want to give the user the ability to click a check box. By clicking the check box, information from say control 1 on form 1, will automatically be put in control 2 on form 2, in essence I want to link controls on two seperate forms in the same database. Help is greatly appreciated.
 

Both forms will need to be loaded for this to work

Private Sub Check2_Click()

Dim MyValue As String

If Check2.Value <> 0 Then
Me.Text0.SetFocus
MyValue = Me.Text0.Text
Application.Forms(&quot;Form2&quot;).SetFocus
Application.Forms(&quot;form2&quot;).Controls(&quot;Text1&quot;).SetFocus
Application.Forms(&quot;Form2&quot;).Controls(&quot;Text1&quot;).Text = MyValue
End If

End Sub

Good Luck
 
Put the following public sub in Form2:

Public Sub NewData(strNewData As String)
txt2.Text = strNewData
End Sub

Put this call or something similar in Form1:

Private Sub Check1_Click()

If Check1.Value = vbChecked Then
Call Form2.NewData(txt1.Text)
End If
Form2.Show

End Sub

The Form2.Show is only added to make the form visible so you can see the result. It works without the .Show, but you won't see it until the form is shown. Note this also causes form2 to be loaded if it has not been already (Form_Load executes)


 

djsiders, Mobuto states in their question

I want to link controls on two seperate forms in the same database

Mobuto, I took this to be access that you are working with, am I correct?

 

Then you can use my code (or something like it) but I would suggest that you set the focus back to form1 and as part of the code I would also add an else clause so that they can unclick the checkbox and the value of the textbox on form2 will be cleared.

Good Luck
 
Is this the right procedure to clear the infomation

ElseIf Check2.Value = 0 then
MyValue.clear
 
Application.Forms(&quot;Form2&quot;).SetFocus
Application.Forms(&quot;form2&quot;).Controls(&quot;Text1&quot;).SetFocus
Application.Forms(&quot;Form2&quot;).Controls(&quot;Text1&quot;).Text = &quot;&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top