Hi all,
I have posted this question ealier, but I think I didn't make it clear enough.
I'm creating a form where users can choose field(s) for a report. What I try to do is when users select a table name, all fields in that table will show up in a list box, but when I select one, there is an error message.
It said, Compile error: User-defined type not define
I don't know how to fix it. Please help!!!
Here is the code:
[COLOR=red yellow]Private Sub cboTable_AfterUpdate()[/color]
On Error GoTo Err_cboTable_AfterUpdate
Dim [COLOR=yellow blue]dbs As DAO.Database[/color] ,tdf As DAO.TableDef
Dim fld As DAO.Field, rst As DAO.Recordset
Dim tbl As String
tbl = Forms!frmLocalAuthority!cboTable
' Return reference to current database.
Set dbs = CurrentDb
' Return reference to Employees table.
Set tdf = dbs.TableDefs(tbl)
DoCmd.SetWarnings False
DoCmd.RunSQL ("Delete * from TableFields")
DoCmd.SetWarnings True
Set rst = dbs.OpenRecordset("TableFields", dbOpenDynaset)
' Enumerate all fields in Fields collection of TableDef object.
For Each fld In tdf.Fields
If fld.Type >= 1 And fld.Type <= 8 Or fld.Type = 10 Then
rst.AddNew
rst!FieldName = fld.Name
rst!FieldType = fld.Type
rst.Update
End If
Next fld
Set dbs = Nothing
'cboFieldName1.Requery
'cboFieldName2.Requery
'cboFieldName3.Requery
lstLocalAuthority.Requery
'reset
Exit_cboTable_AfterUpdate:
Exit Sub
I have posted this question ealier, but I think I didn't make it clear enough.
I'm creating a form where users can choose field(s) for a report. What I try to do is when users select a table name, all fields in that table will show up in a list box, but when I select one, there is an error message.
It said, Compile error: User-defined type not define
I don't know how to fix it. Please help!!!
Here is the code:
[COLOR=red yellow]Private Sub cboTable_AfterUpdate()[/color]
On Error GoTo Err_cboTable_AfterUpdate
Dim [COLOR=yellow blue]dbs As DAO.Database[/color] ,tdf As DAO.TableDef
Dim fld As DAO.Field, rst As DAO.Recordset
Dim tbl As String
tbl = Forms!frmLocalAuthority!cboTable
' Return reference to current database.
Set dbs = CurrentDb
' Return reference to Employees table.
Set tdf = dbs.TableDefs(tbl)
DoCmd.SetWarnings False
DoCmd.RunSQL ("Delete * from TableFields")
DoCmd.SetWarnings True
Set rst = dbs.OpenRecordset("TableFields", dbOpenDynaset)
' Enumerate all fields in Fields collection of TableDef object.
For Each fld In tdf.Fields
If fld.Type >= 1 And fld.Type <= 8 Or fld.Type = 10 Then
rst.AddNew
rst!FieldName = fld.Name
rst!FieldType = fld.Type
rst.Update
End If
Next fld
Set dbs = Nothing
'cboFieldName1.Requery
'cboFieldName2.Requery
'cboFieldName3.Requery
lstLocalAuthority.Requery
'reset
Exit_cboTable_AfterUpdate:
Exit Sub