i have the following code in a form, basically when the user picks a table from a combo box it will populate a list box with the fields present...now if more than one person is using this form it will delete the other persons table (and hence he cant continue using the form without errors)...
can anyone help on a method to solve this.
Private Sub cboTable_afterupdate()
On Error GoTo Err_cboTable_AfterUpdate
Dim dbs As DAO.Database, tdf As DAO.TableDef
Dim fld As DAO.Field, rst As DAO.Recordset
Dim tbl As String, k As Integer
tbl = Forms![frm Advanced Search]!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 usystablefields"
DoCmd.SetWarnings True
Set rst = dbs.OpenRecordset("usystablefields", 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
'reset
lstField.Requery
Me.Controls("lstField"
.Visible = True
For k = 1 To lstField.ListCount - 1
lstField.Selected(k) = True
Next k
For k = 3 To lstField.ListCount - 1
lstField.Selected(k) = False
Next k
lstField.Requery
can anyone help on a method to solve this.
Private Sub cboTable_afterupdate()
On Error GoTo Err_cboTable_AfterUpdate
Dim dbs As DAO.Database, tdf As DAO.TableDef
Dim fld As DAO.Field, rst As DAO.Recordset
Dim tbl As String, k As Integer
tbl = Forms![frm Advanced Search]!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 usystablefields"
DoCmd.SetWarnings True
Set rst = dbs.OpenRecordset("usystablefields", 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
'reset
lstField.Requery
Me.Controls("lstField"
For k = 1 To lstField.ListCount - 1
lstField.Selected(k) = True
Next k
For k = 3 To lstField.ListCount - 1
lstField.Selected(k) = False
Next k
lstField.Requery