2016-07-15 3 views
1

以下の関数が '.Append fld'を実行すると、エラー3057が生成されます。完全修飾名が必要ですが、このメソッドは私にエスケープしていると思われます。この関数を呼び出すsubはstrTableName "tbl_elements"を通り過ぎていますが、この関数では十分ではありません。操作がリンクテーブルでサポートされていない

リンクテーブルに正常に到達した別のビットのコードをフィッティングしようとしました。 HansUpの助けを借りて

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 

答えて

0

以下の問題の

CurrentDb.Execute "ALTER TABLE [" & CurrentDb.TableDefs(strImportHoldingTable).Connect & "].[" & strImportHoldingTable & "] DROP COLUMN romis_tran_id;" 

機能は、私がリンクテーブルを変更する問題を解決しました。新しい問題は、[連番]フィールドがコンパクトでなく1にリセットされておらず、勤務時間中にはできないバックエンドに修復されるということです。

Public Function resetAutoNumber(ByVal strTableName As String, ByVal strFieldName As String, ByVal strIndexName As String) As Boolean 
On Error GoTo ErrTrap 

Dim db As DAO.Database 
Dim fld As DAO.Field 
Dim tdef As DAO.TableDef 
Dim strDbPath As String 

strDbPath = Mid(CurrentDb.TableDefs(strTableName).Connect, 11) 

Set db = DBEngine.OpenDatabase(strDbPath) 
Set tdef = db.TableDefs(strTableName) 
Set fld = tdef.CreateField(strFieldName, dbLong) 
Set ind = tdef.CreateIndex(strIndexName) 

'clear table 
db.Execute "DELETE * FROM " & strTableName 
'delete index 
tdef.Indexes.Delete strIndexName 
'delete field 
tdef.Fields.Delete strFieldName 
're-create field 
    With fld 
     .Attributes = .Attributes Or dbAutoIncrField 
     .OrdinalPosition = 0 
    End With 
    With tdef.Fields 
     .Append fld 
     .Refresh 
    End With 
'recreate index 
ind.Fields.Append ind.CreateField(strIndexName) 
tdef.Indexes.Append ind 

Set ind = Nothing 
Set fld = Nothing 
Set tdef = Nothing 
Set db = Nothing 

ExitHere: 
Exit Function 
ErrTrap: 
MsgBox Err.description 
Resume ExitHere 

End Function 
関連する問題