当我运行这段代码,我碰到一个“开放形式操作被取消”与2501错误代码行就被逮住时,我debbug是DoCmd.RunSQL(要求)错误2501 VBA存取权限
Function Compare()
Dim oDB As DAO.Database
Dim oRst As DAO.Recordset
Dim nbligne As Long
Dim Req As String
Dim default As String
Dim tables As String
Dim table
Dim i As Integer
Dim champ As String
Dim j As Integer
Set oDB = CurrentDb
Set oRst = oDB.OpenRecordset("SELECT Count(*) FROM CELLCAC;")
nbligne = oRst.Fields(0).Value
Set oRs = CurrentDb.OpenRecordset("CELLCAC")
Set fs = CreateObject("Scripting.FileSystemObject")
Set fldr = fs.getfolder("C:\Users\Documents\Application\Application_vba\Delta")
Set fls = fldr.files
Set fld = CurrentDb.OpenRecordset("TABLES_A_VERIFIER_DEFAULT")
For Each fl In fls
If fl Like "*.txt" Then
source = Left(fl.Name, Len(fl.Name) - 4)
tables = source
default = "DEFAULT_" & tables
table = CurrentDb.OpenRecordset(default)
For i = 0 To table.Count - 1
champ = table(i).Name
Req = "INSERT INTO DELTA_DEFAULT(BSCNAME, CELLNAME, MO, PARAMETRE ,DEFAULT ,RESEAU)" _
& "select DISTINCT [" & tables & "]![BSCNAME], [" & tables & "]![CELLNAME],('" & tables & "'), ('" & champ & "') ,[" & default & "]![" & champ & "],[" & tables & "]![" & champ & "] " _
& " from (" & tables & ") INNER join (" & default & ") on (" & default & ".Zone = " & tables & ".Zone) " _
& " Where [" & default & "]![" & champ & "] <> [" & tables & "]![" & champ & "];"
DoCmd.RunSQL (Req)
Next i
End If
Next fl
End Function
上
当您尝试DoCmd时,发布'Req'中的sql值。 –
您报告了错误消息参考打开窗体,但您的代码没有提及窗体。建议您将VBA过程与任何表单事件隔离开来。至少Access可能会给你一个错误信息,它更好地描述了INSERT语句的问题。 – HansUp