我想我可能已经解决了这个插入到SQL表问题。我一直在打SYNTAX ERROR问题,它突出显示了整个QDF.SQL =“INSERT INTO .....部分。我试图解决我做错了什么。任何专家都可以发现我的问题是什么?插入语法问题
。Public Function Update()
Dim cdb As DAO.Database, qdf As DAO.QueryDef
Dim rs As Recordset
Dim err As DAO.Error
Const DestinationTableName = "AC_CDData"
Const ConnectionString = _
"ODBC;" & _
"Driver={SQL Server Native Client 10.0};" & _
"Server=GAALPSVR031B\P003,49503;" & _
"Database=DB;" & _
"UID=ID;" & _
"PWD=PW;"
Set cdb = CurrentDb
Set qdf = cdb.CreateQueryDef("")
Set rs = CurrentDb.OpenRecordset("CDData", dbOpenTable)
qdf.Connect = ConnectionString
Do While Not rs.EOF
qdf.SQL = "INSERT INTO ac_cddata_1(EmployeeID, EmployeeName, Region, District, Function1, Gender, EEOC, Division, Center, MeetingReadinessLevel, ManagerReadinessLevel, EmployeeFeedback, DevelopmentForEmployee1, DevelopmentForEmployee2, DevelopmentForEmployee3, DevelopmentForEmployee4, DevelopmentForEmployee5, Justification, Changed, JobGroupCode, JobDesc, JobGroup) " & _
"Values (" & _
"'" & rs.EmployeeID & "', " & _
"'" & rs.EmployeeName & "', " & _
"'" & rs.Region & "', " & _
"'" & rs.District & "', " & _
"'" & rs.Function1 & "', " & _
"'" & rs.Gender & "', " & _
"'" & rs.EEOC & "', " & _
"'" & rs.Division & "', " & _
"'" & rs.Center & "', " & _
"'" & rs.MeetingReadinessLevel & "', " & _
"'" & rs.ManagerReadinessLevel & "', " & _
"'" & rs.EmployeeFeedback & "', " & _
"'" & rs.DevelopmentForEmployee1 & "', " & _
"'" & rs.DevelopmentForEmployee2 & "', " & _
"'" & rs.DevelopmentForEmployee3 & "', " & _
"'" & rs.DevelopmentForEmployee4 & "', " & _
"'" & rs.DevelopmentForEmployee5 & "', " & _
"'" & rs.Justification & "', " & _
"'" & rs.Changed & "', " & _
"'" & rs.JobGroupCode & "', " & _
"'" & rs.JobDesc & "', " & _
"'" & rs.JobGroup"')"
qdf.ReturnsRecords = False
On Error GoTo Update_qdfError
qdf.Execute dbFailOnError
On Error GoTo 0
rs.MoveNext
Loop
rs.Close
Set qdf = Nothing
Set cdb = Nothing
Set rs = Nothing
Exit Function
Update_qdfError:
For Each err In DAO.Errors
MsgBox err.Description, vbCritical, "Error " & err.Number
Next
End Function
现在解决了这个问题我得到一个TYPE MISMATCH错误,它突出显示SET RS = CURRENTDB.OPENRECORDSET(“CDDATA”,“DBOPENTABLE) – user2119980
然后尝试:set rs = currentdb()。 openRecordset(“CDDATA”,dbOpenDynaset)' – Barranka
不要在DBOPENTABLE周围使用引号,它是一个常量的名称,所以不应该引用 – HansUp