2016-05-17 3 views
-2

に現在のインデックスをコピーするために、私はこれのprogrammを書くしようとしている:アクセスVBA:どのように他のテーブル

 Function funktion() 
     Dim db As DAO.Database 
     Dim rs As DAO.Recordset 
     Dim rt As DAO.Recordset 
     Set db = CurrentDb 

     Set rs = db.OpenRecordset("All") 

Do While Not rs.EOF 


Set rk = db.OpenRecordset("Archive") 

'here I want to copy(append) the current index(of Table"All") into the next free 
index (of table "archive") 


Do something 


    rs.MoveNext 
Loop 

私のプログラムの開発は、私はに「すべて」から現在の行を追加する必要があるだけでうまく機能テーブル「アーカイブ」から次に空いている行。

はあなたの助けが私は別のテーブルにすべてのレコードを追加します。..上記の例では....データにアクセスするには、このADOを使用していないDAOを行うことができますどのように

+0

はい、それはそのようなVBAでイストdoesen't仕事:[すべて] SELECT * FROM [アーカイブ]のINSERT INTO SELECT *; – user3569647

+0

はい、そういうわけではありません:INSERT INTO [アーカイブ] SELECT * FROM [すべて]; – user3569647

+0

はい、それは私が探しているものですが、私はループブロックの現在の行だけを必要とします。 – user3569647

答えて

0

here'sa例をありがとう...しかし、簡単にあなただけの

Dim cnn As New ADODB.Connection 
Dim rs As ADODB.Recordset 
Dim rs2 As ADODB.Recordset 

Set cnn = CurrentProject.Connection 
Set rs = New ADODB.Recordset 
Set rs2 = New ADODB.Recordset 

'open main recordset (TDetPed) 
rs.Open "SELECT TDetPed.* FROM TDetPed WHERE CodPed = " & CodPed & "", cnn, adOpenKeyset, adLockOptimistic 


'open clone table recordset (TDetPedTemp) 
rs2.Open "TDetPedTemp", cnn, adOpenKeyset, adLockOptimistic 

'move to first record of main table 
rs.MoveFirst 

'add record by record in clone table(rs2) from maintable(rs) 
Do Until rs.EOF 
rs2.AddNew 
rs2("CodPed") = rs("CodPed") 
rs2("CodDetPed") = rs("CodDetPed") 
rs2("CodInterno") = rs("CodInterno") 
rs2("DescrDetPed") = rs("DescrDetPed") 
rs2("DescontoDetPed") = rs("DescontoDetPed") 
rs2("CodProd") = rs("CodProd") 
rs2("PreçoDetPed") = rs("PreçoDetPed") 
rs2("QtdeDetPed") = rs("QtdeDetPed") 

'update current added record in clone table 
rs2.Update 

'move to next record in main table 
rs.MoveNext 
'Move para o proximo registro do detalhe do pedido 
Loop 

'close everthing 
rs.Close 
rs2.Close 
cnn.Close 
'clean everthing 
Set rs = Nothing 
Set rs2 = Nothing 
Set cnn = Nothing 
+0

これは私が探していたソリューションです。 – user3569647

0

ちょうど(アクティブ・データObjetcs)をADO DAO(データアクセスObjetcs)を使用して、答え...簡単な例を完了していない...あなたのループ内の現在のレコードを追加することができます。 (詳細https://msdn.microsoft.com/en-us/library/aa261340%28v=vs.60%29.aspx/http://www.utteraccess.com/wiki/index.php/Choosing_between_DAO_and_ADO

Dim db As DAO.Database 
    Dim rs As DAO.Recordset 

    Set db = CurrentDb 
    Set rs = dbsNorthwind.OpenRecordset("Tbl1")  
    rs.AddNew 
    rs!Cidade = "Curitiba" 
    rs!Country = "Brazil"  
    '.... others fields  
    rs.Update 
関連する問題