A
Andy
Help, I have a "3211 Error", could not lock table, because it is already
used in form.
How to refresh a table shown on a form, when it is altered by a VBA
procedure called from the same form?
VBA code follow
Thanks
Andy
-------------------------------------------
FORM Subroutines
Private Sub Form_Load()
'Subroutine that shows 3211 Error, because table is shown in form?
Call Mod_TableFields
End Sub
-------------------------------------------
Private Sub TableName_Click()
Response = MsgBox("Marry: " & Me.TableName & " ? ", vbYesNo, "Marry a File")
If Response = vbYes Then
'Call MARRIED(Me.TableName)
' Subroutine that shows 3211 Error, because table is shown in form?
Call Mod_TableFields
Refresh
End If
End Sub
-------------------------------------------
MODULE 1 SUBROUTINES
Sub Mod_TableFields()
On Error GoTo Error_Handler
Dim ThisDB As DAO.Database
Dim RS As DAO.Recordset
Set ThisDB = CurrentDb
' Drop field table, so it can be rebuilt
ThisDB.Execute "DROP TABLE T_FIELDS;"
STEP1_BYPASS:
'Create clean empty field table
ThisDB.Execute "CREATE TABLE T_FIELDS (Table_name TEXT, Field_name TEXT,
CNTRecs double );"
' Open that clean empty table
Set RS = ThisDB.OpenRecordset("T_FIELDS")
' Go through each of the Access table definitions
For Each tdf In ThisDB.TableDefs
' Go through each of the Access field definitions
For Each fld In tdf.Fields
RS.AddNew
RS!Table_name = tdf.Name
RS!CNTRecs = tdf.RecordCount
RS!FIELD_NAME = fld.Name
RS.Update
Next fld
Next tdf
'Close the new field table
RS.Close
'Empty the reference
Set RS = Nothing
' Delete the table file, to rebuild it fresh and clean
' 3211 Error shown because table is shown in form?
ThisDB.Execute "DROP TABLE T_TABLES"
' Error handler skips this step when table not dropped because of 3211
error.
' Query & Group field information
ThisDB.Execute "SELECT Table_name, CNTRecs, Count(Table_name) AS CNTFields
INTO T_TABLES " & _
" FROM T_FIELDS GROUP BY Table_name, CNTRecs ORDER BY Table_name; "
STEP2_BYPASS:
' Leave subroutine
Exit Sub
'ERROR HANDLER
Error_Handler:
If Err <> 0 Then
MsgBox Err.Number & " " & Err.Source & "->" & Err.Description, ,
"Error"
If Err = 3376 Then
Resume STEP1_BYPASS
End If
If Err = 0 Then
Resume STEP2_BYPASS
End If
End If
End Sub
used in form.
How to refresh a table shown on a form, when it is altered by a VBA
procedure called from the same form?
VBA code follow
Thanks
Andy
-------------------------------------------
FORM Subroutines
Private Sub Form_Load()
'Subroutine that shows 3211 Error, because table is shown in form?
Call Mod_TableFields
End Sub
-------------------------------------------
Private Sub TableName_Click()
Response = MsgBox("Marry: " & Me.TableName & " ? ", vbYesNo, "Marry a File")
If Response = vbYes Then
'Call MARRIED(Me.TableName)
' Subroutine that shows 3211 Error, because table is shown in form?
Call Mod_TableFields
Refresh
End If
End Sub
-------------------------------------------
MODULE 1 SUBROUTINES
Sub Mod_TableFields()
On Error GoTo Error_Handler
Dim ThisDB As DAO.Database
Dim RS As DAO.Recordset
Set ThisDB = CurrentDb
' Drop field table, so it can be rebuilt
ThisDB.Execute "DROP TABLE T_FIELDS;"
STEP1_BYPASS:
'Create clean empty field table
ThisDB.Execute "CREATE TABLE T_FIELDS (Table_name TEXT, Field_name TEXT,
CNTRecs double );"
' Open that clean empty table
Set RS = ThisDB.OpenRecordset("T_FIELDS")
' Go through each of the Access table definitions
For Each tdf In ThisDB.TableDefs
' Go through each of the Access field definitions
For Each fld In tdf.Fields
RS.AddNew
RS!Table_name = tdf.Name
RS!CNTRecs = tdf.RecordCount
RS!FIELD_NAME = fld.Name
RS.Update
Next fld
Next tdf
'Close the new field table
RS.Close
'Empty the reference
Set RS = Nothing
' Delete the table file, to rebuild it fresh and clean
' 3211 Error shown because table is shown in form?
ThisDB.Execute "DROP TABLE T_TABLES"
' Error handler skips this step when table not dropped because of 3211
error.
' Query & Group field information
ThisDB.Execute "SELECT Table_name, CNTRecs, Count(Table_name) AS CNTFields
INTO T_TABLES " & _
" FROM T_FIELDS GROUP BY Table_name, CNTRecs ORDER BY Table_name; "
STEP2_BYPASS:
' Leave subroutine
Exit Sub
'ERROR HANDLER
Error_Handler:
If Err <> 0 Then
MsgBox Err.Number & " " & Err.Source & "->" & Err.Description, ,
"Error"
If Err = 3376 Then
Resume STEP1_BYPASS
End If
If Err = 0 Then
Resume STEP2_BYPASS
End If
End If
End Sub