我不确定我是否错过了什么,我试图找到语法错误,但我根本无法想象,也许我的眼睛流血,因为我花了2个小时试图得到怎么了。
表单代码:
Option Compare Database
Private Sub btnZatwierdzAccessories_Click()
Dim strSQLdeleteAccessories As String
Dim strSQLzm1accessoriesA As String
Dim strSQLzm1accessoriesB As String
Dim strSQLzm1accessoriesC As String
Dim strSQLzm1accessoriesD As String
Dim strSQLzm2accessoriesA As String
Dim strSQLzm2accessoriesB As String
Dim strSQLzm2accessoriesC As String
Dim strSQLzm2accessoriesD As String
Dim strSQLzm3accessoriesA As String
Dim strSQLzm3accessoriesB As String
Dim strSQLzm3accessoriesC As String
Dim strSQLzm3accessoriesD As String
strSQLdeleteAccessories = "DELETE * FROM [dbGrafikAccessories] WHERE dataAccessories = #" & Format(Me!txtDataAccessories, "d-m-yyyy") & "#;"
strSQLzm1accessoriesA = "INSERT INTO dbGrafikAccessories (imieNazwisko, numerTelefonu, zmiana, praca, zaklad, godzina, dataAccessories, dataAccessoriesDo) VALUES ('" & Me!listZM1accessoriesA.Column(0) & "', '" & Me!listZM1accessoriesA.Column(1) & "', 'zm1', 'automatyk', 'accessories', '06001400', #" & Format(Me!txtDataAccessories, "d-m-yyyy") & "#, #" & Format(Me!txtDataAccessoriesDo, "d-m-yyyy") & "#);"
strSQLzm1accessoriesB = "INSERT INTO dbGrafikAccessories (imieNazwisko, numerTelefonu, zmiana, praca, zaklad, godzina, dataAccessories, dataAccessoriesDo) VALUES ('" & Me!listZM1accessoriesB.Column(0) & "', '" & Me!listZM1accessoriesB.Column(1) & "', 'zm1', 'piankowanie', 'accessories', '06001400', #" & Format(Me!txtDataAccessories, "d-m-yyyy") & "#, #" & Format(Me!txtDataAccessoriesDo, "d-m-yyyy") & "#);"
strSQLzm1accessoriesC = "INSERT INTO dbGrafikAccessories (imieNazwisko, numerTelefonu, zmiana, praca, zaklad, godzina, dataAccessories, dataAccessoriesDo) VALUES ('" & Me!listZM1accessoriesC.Column(0) & "', '" & Me!listZM1accessoriesC.Column(1) & "', 'zm1', 'szycie', 'accessories', '06001400', #" & Format(Me!txtDataAccessories, "d-m-yyyy") & "#, #" & Format(Me!txtDataAccessoriesDo, "d-m-yyyy") & "#);"
strSQLzm1accessoriesD = "INSERT INTO dbGrafikAccessories (imieNazwisko, numerTelefonu, zmiana, praca, zaklad, godzina, dataAccessories, dataAccessoriesDo) VALUES ('" & Me!listZM1accessoriesD.Column(0) & "', '" & Me!listZM1accessoriesD.Column(1) & "', 'zm1', 'dodatkowy', 'accessories', '06001400', #" & Format(Me!txtDataAccessories, "d-m-yyyy") & "#, #" & Format(Me!txtDataAccessoriesDo, "d-m-yyyy") & "#);"
strSQLzm2accessoriesA = "INSERT INTO dbGrafikAccessories (imieNazwisko, numerTelefonu, zmiana, praca, zaklad, godzina, dataAccessories, dataAccessoriesDo) VALUES ('" & Me!listZM2accessoriesA.Column(0) & "', '" & Me!listZM2accessoriesA.Column(1) & "', 'zm2', 'automatyk', 'accessories', '14002200', #" & Format(Me!txtDataAccessories, "d-m-yyyy") & "#, #" & Format(Me!txtDataAccessoriesDo, "d-m-yyyy") & "#);"
strSQLzm2accessoriesB = "INSERT INTO dbGrafikAccessories (imieNazwisko, numerTelefonu, zmiana, praca, zaklad, godzina, dataAccessories, dataAccessoriesDo) VALUES ('" & Me!listZM2accessoriesB.Column(0) & "', '" & Me!listZM2accessoriesB.Column(1) & "', 'zm2', 'piankowanie', 'accessories', '14002200', #" & Format(Me!txtDataAccessories, "d-m-yyyy") & "#, #" & Format(Me!txtDataAccessoriesDo, "d-m-yyyy") & "#);"
strSQLzm2accessoriesC = "INSERT INTO dbGrafikAccessories (imieNazwisko, numerTelefonu, zmiana, praca, zaklad, godzina, dataAccessories, dataAccessoriesDo) VALUES ('" & Me!listZM2accessoriesC.Column(0) & "', '" & Me!listZM2accessoriesC.Column(1) & "', 'zm2', 'szycie', 'accessories', '14002200', #" & Format(Me!txtDataAccessories, "d-m-yyyy") & "#, #" & Format(Me!txtDataAccessoriesDo, "d-m-yyyy") & "#);"
strSQLzm2accessoriesD = "INSERT INTO dbGrafikAccessories (imieNazwisko, numerTelefonu, zmiana, praca, zaklad, godzina, dataAccessories, dataAccessoriesDo) VALUES ('" & Me!listZM2accessoriesD.Column(0) & "', '" & Me!listZM2accessoriesD.Column(1) & "', 'zm2', 'dodatkowy', 'accessories', '14002200', #" & Format(Me!txtDataAccessories, "d-m-yyyy") & "#, #" & Format(Me!txtDataAccessoriesDo, "d-m-yyyy") & "#);"
strSQLzm3accessoriesA = "INSERT INTO dbGrafikAccessories (imieNazwisko, numerTelefonu, zmiana, praca, zaklad, godzina, dataAccessories, dataAccessoriesDo) VALUES ('" & Me!listZM3accessoriesA.Column(0) & "', '" & Me!listZM3accessoriesA.Column(1) & "', 'zm3', 'automatyk', 'accessories', '22000600', #" & Format(Me!txtDataAccessories, "d-m-yyyy") & "#, #" & Format(Me!txtDataAccessoriesDo, "d-m-yyyy") & "#);"
strSQLzm3accessoriesB = "INSERT INTO dbGrafikAccessories (imieNazwisko, numerTelefonu, zmiana, praca, zaklad, godzina, dataAccessories, dataAccessoriesDo) VALUES ('" & Me!listZM3accessoriesB.Column(0) & "', '" & Me!listZM3accessoriesB.Column(1) & "', 'zm3', 'piankowanie', 'accessories', '22000600', #" & Format(Me!txtDataAccessories, "d-m-yyyy") & "#, #" & Format(Me!txtDataAccessoriesDo, "d-m-yyyy") & "#);"
strSQLzm3accessoriesC = "INSERT INTO dbGrafikAccessories (imieNazwisko, numerTelefonu, zmiana, praca, zaklad, godzina, dataAccessories, dataAccessoriesDo) VALUES ('" & Me!listZM3accessoriesC.Column(0) & "', '" & Me!listZM3accessoriesC.Column(1) & "', 'zm3', 'szycie', 'accessories', '22000600', #" & Format(Me!txtDataAccessories, "d-m-yyyy") & "#, #" & Format(Me!txtDataAccessoriesDo, "d-m-yyyy") & "#);"
strSQLzm3accessoriesD = "INSERT INTO dbGrafikAccessories (imieNazwisko, numerTelefonu, zmiana, praca, zaklad, godzina, dataAccessories, dataAccessoriesDo) VALUES ('" & Me!listZM3accessoriesD.Column(0) & "', '" & Me!listZM3accessoriesD.Column(1) & "', 'zm3', 'dodatkowy', 'accessories', '22000600', #" & Format(Me!txtDataAccessories, "d-m-yyyy") & "#, #" & Format(Me!txtDataAccessoriesDo, "d-m-yyyy") & "#);"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQLdeleteAccessories
DoCmd.RunSQL strSQLzm1accessoriesA
DoCmd.RunSQL strSQLzm1accessoriesB
DoCmd.RunSQL strSQLzm1accessoriesC
DoCmd.RunSQL strSQLzm1accessoriesD
DoCmd.RunSQL strSQLzm2accessoriesA
DoCmd.RunSQL strSQLzm2accessoriesB
DoCmd.RunSQL strSQLzm2accessoriesC
DoCmd.RunSQL strSQLzm2accessoriesD
DoCmd.RunSQL strSQLzm3accessoriesA
DoCmd.RunSQL strSQLzm3accessoriesB
DoCmd.RunSQL strSQLzm3accessoriesC
DoCmd.RunSQL strSQLzm3accessoriesD
DoCmd.SetWarnings True
End Sub
debug将我重定向到以下行:
DoCmd.RunSQL strSQLzm1accessoriesA
显示错误消息:
Run-time error '3075':
Syntax error in date in query expression '#'.
答案 0 :(得分:1)
首先,您的日期格式应为:
.. #" & Format(Me!txtDataAccessories, "yyyy\/mm\/dd") & "#,
其次,如果文本框为空,则SQL将失败。
所以写出要创建的SQL进行调试:
Debug.Print strSQLzm1accessoriesA
然后研究输出。