|
▼さつき さん:
ごめんなさい。ADOでしたね。
ADOには「FindFirst」メソッドがないので「Find」メソッドを使うか
「Filter」で新規か更新か判断する事になります。
以下参考にして下さい。
Public Function 横並び()
Dim cn As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim rs2 As ADODB.Recordset
Dim cr As String
Dim I As Long
Dim J As Long
Application.Echo False
DoCmd.Hourglass True
Set cn = Application.CurrentProject.Connection
Set rs1 = New ADODB.Recordset
Set rs2 = New ADODB.Recordset
rs1.Open "list", cn, adOpenStatic, adLockReadOnly
rs2.Open "listyoko", cn, adOpenKeyset, adLockOptimistic
Do Until rs1.EOF
If Not IsNull(rs1![区分].Value) Then
'フィルタを掛けて新規か追加か判断
rs2.Filter = "契約者 ='" & rs1![契約者] & "'"
'データなし(新規)
If rs2.EOF Then
rs2.AddNew
For I = 1 To 4
rs2(I - 1) = rs1(I)
Next I
'データあり(追加)
Else
J = 0
'空のフィールドを検索
Do Until rs2(J) = "" Or IsNull(rs2(J))
J = J + 1
Loop
For I = 0 To 2
rs2(I + J) = rs1(I + 2)
Next
End If
'更新
rs2.Update
End If
rs1.MoveNext
Loop
'オブジェクトの解放
rs1.Close: Set rs1 = Nothing
rs2.Close: Set rs2 = Nothing
cn.Close: Set cn = Nothing
End Function
|
|