1
當下面的函數執行'.Append fld'時,它會生成錯誤3057.我懷疑需要一個完全限定的名稱,但該方法正在逃避我。調用此函數的子程序通過strTableName「tbl_elements」的方式進行傳遞,但這對於此函數來說不夠用。在鏈接表上不支持的操作
我已經嘗試裝配另一個已成功到達鏈接表的代碼。
CurrentDb.Execute "ALTER TABLE [" & CurrentDb.TableDefs(strImportHoldingTable).Connect & "].[" & strImportHoldingTable & "] DROP COLUMN romis_tran_id;"
功能的問題下面
Public Function CreateAutoNumberField(ByVal strTableName As String, ByVal strFieldName As String) As Boolean
On Error GoTo Err_CreateAutoNumberField
Dim db As DAO.Database
Dim fld As DAO.Field
Dim tdef As DAO.TableDef
Set db = Application.CurrentDb
Set tdef = db.TableDefs(strTableName)
Set fld = tdef.CreateField(strFieldName, dbLong)
With fld
.Attributes = .Attributes Or dbAutoIncrField
End With
With tdef.Fields
.Append fld
.Refresh
End With
CreateAutoNumberField = True
Exit_CreateAutoNumberField:
Set fld = Nothing
Set tdef = Nothing
Set db = Nothing
Exit Function
Err_CreateAutoNumberField:
CreateAutoNumberField = False
With Err
MsgBox "Error " & .Number & vbCrLf & .description, vbOKOnly Or vbCritical, "CreateAutoNumberField"
End With
Resume Exit_CreateAutoNumberField
End Function