|
▼Satsuki さん:
こんにちは。
うーん、Deleteの所がうまくいっていないのが残念ですが、
とりあえずは 855さんがご提示して下さった Execute で回避できそうですね。
以下、ご参考になれば幸いです。
Option Compare Database
Option Explicit
Dim cn As ADODB.Connection
Sub keisan2()
Dim rs As ADODB.Recordset
Dim strSQL As String
Set cn = CurrentProject.Connection
Call WorkDelete
Set rs = CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM データ"
rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly
Do Until rs.EOF
strSQL = "INSERT INTO TOP5 (kyotenmei, kyoriX, kyoriY)" _
& "SELECT TOP 5 拠点名, [X1] - " & rs![x] & ", [Y1] - " & rs![y] & " " _
& "FROM 位置 " _
& "ORDER BY Sqr((Abs(" & rs![x] & "- [x1])*30.82)^2 " _
& "+(Abs(" & rs![y] & "- [y1])*25.15)^2)/1000 ASC;"
cn.Execute strSQL
rs.MoveNext
Loop
rs.Close: Set rs = Nothing
cn.Close: Set cn = Nothing
End Sub
Function WorkDelete()
Dim strSQL As String
strSQL = "DELETE FROM TOP5"
cn.Execute strSQL
strSQL = "DELETE FROM 距離"
cn.Execute strSQL
End Function
|
|