2

I want to create two CombiFields in an Access Form:

  • the first one should show all Table Names of the DB in a dropdown(*)
  • and the second one should show all column names from the Table which has been choosed in the first Combifield.

Any ideas?

(*) I already have the first Code:

SELECT MSysObjects.Name
FROM MSysObjects
WHERE (((MSysObjects.Flags)=0) AND ((MSysObjects.Type)=1));

2 Answers 2

3

Set the RowSource property of the combobox to the name of the table (=ComboBoxTable).

Then set the RowSourceType property to: Field List

Private Sub ComboBoxTable_AfterUpdate()

    Me!ComboBoxFields.RowSource = Me!ComboBoxTable.Value

End Sub
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but actually i dont really get it. Should i write "=ComboBoxTable" in the RowSource? Or is there also any SQL Code which works?
No, use the AfterUpdate event of the table combobox. See edit.
0

try bellow code in AfterUpdate of first combo

Private Sub Combo0_AfterUpdate()
Dim TableName As String
TableName = Me.Combo0.Value
Dim rs As New ADODB.Recordset
Set rs = CurrentProject.Connection.OpenSchema(adSchemaColumns, Array(Empty, Empty, TableName))
Dim fldname As String
rs.MoveFirst
Do Until rs.EOF
fldname = fldname & rs!Column_Name & ";"
rs.MoveNext
Loop
Me.Combo2.RowSource = fldname
Me.Combo2.RowSourceType = "Value List"
Me.Combo2.Requery
End Sub

4 Comments

Unfortunately I still cant get it running...To sum up: The first Combobox (Combo1) shows the TableNames so far. I add the AfterUpdate Code from nazark to that. And I add AfterUpdate Code from Gustav to the second Combobox (Combo2). Now I get a Compile Error for the Code "Dim rs As New ADODB.Recordset" Thanks in advance! :)
You cannot mix and toss everything just like that. You need only and nothing more than my single line of code (above). The second combobox needs zero code.
you need to add Reference to microsoft activex Data Object library 2.6 from the tool menu of code windows
the code above is to get column name in the second combo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.