Originally Posted by
ssanfu
I think I misunderstood what you were doing.
You have an unbound combo box where the row source is the tables of the database.
You select a table from the combo box, which changes the record source of a sub-form.
Would you post the code you are using?
Yes that's correct. I get the list of tables from another function that populations the combobox onform Load.
Here is the code for the combobox AfterUpdate event and the function it calls. Not I'll be making the function general later; I'm just trying to get the functionality I want first, then I'll refactor it.
Code:
Private Sub cboArchivedTableList_AfterUpdate()
ChangeArchiveTable (cboArchivedTableList.Value)
DoCmd.Close acForm, Me.Name ' (form name is "startup")
DoCmd.OpenForm "frmArchiveViewer", acNormal, , , , acWindowNormal
End Sub
Code:
Sub ChangeArchiveTable(newTable As String)
Dim db As Database
Dim t As TableDef
Dim originalConnect As String
Set db = CurrentDb
originalConnect = CurrentDb.TableDefs("tblArchive").Connect
db.TableDefs.Delete "tblArchive"
Set t = db.CreateTableDef("tblArchive")
With t
.Connect = originalConnect
.SourceTableName = newTable
End With
db.TableDefs.Append t
End Sub