2016-04-04 23 views
0

フォームからレコードをコピーしようとしています。ボタンの後ろに私のコードは次のようになります。RecordsetCloneがODBCエラーの原因です

With Me.RecordsetClone 
    .AddNew 
     !TableField1 = Me.CorrespondingTextboxName1 
     !TableField2 = Me.CorrespondingTextboxName2 
     … etc for the rest of the fields     
    .Update 
    .Bookmark = .LastModified 
End With 

問題がある、私は.Updateラインに到達したとき、私はODBC Call Failedを言うなエラーになっています。

コードをステップ実行すると、各フィールドが正しく解決されているように見えますが、そのように思われないUpdateステートメントだけです。

これがなぜ起こるのか、どのように修正するのか、考えてください。

答えて

0

実際は答えはありませんが、コメントのコードは大変です。

DBEngine.Errorsコレクションを使用して、「ODBC Call Failed」の詳細を確認できます。あなたのエラーハンドラに次のコードを実行します。

Dim errX As DAO.Error 

For Each errX In Errors 
    Debug.Print errX.Number & ": " & errX.Description 
Next errX 

は編集:それが動作するとき、あなたはおそらく、おそらくあなたは、IDをコピー

Me.Bookmark = .LastModified 
0

をしたいですか?

ここでボタンのクリックからレコードをコピーするために、実績のある機能です:

Private Sub btnCopy_Click() 

    Dim rstSource As DAO.Recordset 
    Dim rstInsert As DAO.Recordset 
    Dim fld   As DAO.Field 

    If Me.NewRecord = True Then Exit Sub 

    Set rstInsert = Me.RecordsetClone 
    Set rstSource = rstInsert.Clone 
    With rstSource 
    If .RecordCount > 0 Then 
     ' Go to the current record. 
     .Bookmark = Me.Bookmark 
     With rstInsert 
     .AddNew 
      For Each fld In rstSource.Fields 
      With fld 
       If .Attributes And dbAutoIncrField Then 
       ' Skip Autonumber or GUID field. 
       Else 
       ' Copy field content. 
       rstInsert.Fields(.Name).Value = .Value 
       End If 
      End With 
      Next 
     .Update 
     ' Go to the new record and sync form. 
     .MoveLast 
     Me.Bookmark = .Bookmark 
     .Close 
     End With 
    End If 
    .Close 
    End With 

    Set rstInsert = Nothing 
    Set rstSource = Nothing 

End Sub 
関連する問題