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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update unbound form 2

Status
Not open for further replies.

NewTexican

Technical User
Dec 10, 2004
95
US
2 textboxes on a pop up form control other things on the form. These textboxes get their values from the form they pop up from. When the user scrolls through records on the main form with the pop up open I want the pop up to update as well. This is my code for the pop up in form_current

Me.Text18 = Forms![common company].[Company Numeric]
Me.Text20 = Forms![common company]![Company Address T subform].Form![company Address Type]
compnum = Me.Text18
addtype = Me.Text20

When [Company Numeric] & [company Address Type] change on the main form I want these variables to be updated.

Any suggestions???? Thanks in advance.
 
In the AfterUpdate event procedures of the scrolled controls you may try Forms![pop up form].Requery or Forms![pop up form].Recalc.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Figure out what event you want to trigger the updates, such as the Form_Current event or an After_Update event, then tell the popup to update itself:
Code:
Private Sub Form_Current()
  If IsLoaded("Companies Popup") Then
    Forms![Companies Popup].UpdateControls
  End If
End Sub
In the popup form add a public procedure to update the items you need:
Code:
Sub UpdateControls()
  Me.Text18 = Forms![ParentForm].[Company Numeric]
  Me.Text20 = Forms![ParentForm]![subform].Form![Type]
  compnum = Me.Text18
  addtype = Me.Text20
End Sub
Also, if the popup is never loaded unless the parent form is already loaded, you can just set the ControlSource property of the textboxes to the parent form's values, assuming they don't need to be edited:
Code:
ControlSource: =Forms![ParentForm].[Company Numeric]


VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Ok, I added the control source code per vbslammer's suggestion. I added the following code to form_current on the main form:

If CurrentProject.AllForms("company mailout f").IsLoaded = True Then
Forms![company mailout f].[Text18].Requery
Forms![company mailout f].[Text20].Requery
End If

Now all the checkboxes you guys helped me link up to these textboxes don't update.

Private Sub Form_current()
Dim dbs As Database
Dim db As Database
Dim rstable As DAO.Recordset
Dim sqllst1, sqllst2, sqllst3, sqllst4, sqllst5, sqllst6 As String
Dim mail1, mail2, mail3, mail4, mail5, mail6 As Boolean
Dim compnum As Long
Dim addtype As String

compnum = Me.Text18
addtype = Me.Text20

Set db = CurrentDb
Set rstable = db.OpenRecordset("Company-Mailout T", dbOpenDynaset)

sqllst1 = "[company numeric] = " & compnum & " and [address type] = " & "'" & addtype & "'" & " and [mailout] = 'c mailout 1'"
sqllst2 = "[company numeric] = " & compnum & " and [address type] = " & "'" & addtype & "'" & " and [mailout] = 'c mailout 2'"
...

rstable.FindFirst sqllst1
Me!Check12.Value = (Not rstable.NoMatch) And rstable![Send mailout]
rstable.FindFirst sqllst2
Me!Check14.Value = (Not rstable.NoMatch) And rstable![Send mailout]
.......

rstable.Close
End Sub

I couldn't make this work with VBslammer's sql_base code. I don't think I know enough vba yet. How would you suggest I update these checkbox values? Thanks.
 
Change the scope of the Form_Current event on your popup form to Public, then you can call it directly from the parent:
Code:
If CurrentProject.AllForms("company mailout f").IsLoaded Then
  Forms![company mailout f].Form_Current
End If
That way all the code within that event will fire and you don't have to muck around with individual controls from the parent side. You'll have to requery your textboxes in the popup:
Code:
Public Sub Form_Current()
  
  'existing code...
  
  Me.Text18.Requery
  Me.Text20.Requery
  compnum = Me.Text18
  addtype = Me.Text20

  'existing code...

End Sub

VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top