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

Main form control changes RowSource for subform control

Status
Not open for further replies.

williekay

Technical User
Jun 30, 2003
121
0
0
US
Can you have a mainform with a combobox that lists field names from a table, change the RowSource for a textbox in a subform.

Table 1 Table2
NameofFields Mo Ni Mn
Mo
Ni
Mn

Main
combobox > Mo <
Ni
Mn
-------------------
Sub
Textbox >> RowSource = Value of MainForm Combobox <<

Willie
 
How are ya williekay . . .

A TextBox doesn't have a [blue]RowSource[/blue] . . . it has an [blue]ControlSource![/blue]

[purple]Your Thoughts?[/purple]

Calvin.gif
See Ya! . . . . . .
 
Mabye in the afterupdate() of the combo:

Me!Subform.Form!ControlName = Me.cboBox

Pampers [afro]
Just let it go...
 

Code:
Private Sub cmboFields_AfterUpdate()
  Dim strSubForm As String
  Dim strTextBox As String
  'your names go here
  strSubForm = "subFrmNames"
  strTextBox = "txtBxOne"
  Me.Controls(strSubForm).Form.Controls(strTextBox).ControlSource = Me.cmboFields
End Sub

Private Sub Form_Load()
  Dim cmboName As String
  'your combo name here
  cmboName = "cmboFields"
  With Me.Controls(cmboName)
    .ColumnCount = 1
    .BoundColumn = 1
    .RowSourceType = "value list"
    .RowSource = loadCombo("subfrmNames")
  End With
End Sub

Public Function loadCombo(theSubFrmName As String) As String
  Dim rs As DAO.Recordset
  Dim fldField As DAO.Field
  Set rs = Me.Controls(theSubFrmName).Form.RecordsetClone
  For Each fldField In rs.Fields
     loadCombo = loadCombo & fldField.Name & ";"
  Next fldField
  loadCombo = Left(loadCombo, Len(loadCombo) - 1)
  
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top