编辑更新无法在MS Access上运行?

时间:2015-05-31 11:01:28

标签: access-vba

我是MS Access新手。这是一个基本的东西。我正在MS Access表单中执行编辑按钮,但我不断收到运行时错误。这是代码:

CurrentDb.Execute " UPDATE FLIGHT SET " & _
"STD= ' " & Me.Text3 & " ' " & _
",Destination = ' " & Me.Text5 & " ' " & _
",Remark = ' " & Me.Text7 & " ' " & _
",ETD = ' " & Me.Text9 & " ' " & _
",ATD = ' " & Me.Text11 & " ' " & _
",OFBL =  ' " & Me.Text13 & " ' " & _
",CAR= ' " & Me.Text15 & " '  " & _
",Nature = ' " & Me.Text17 & " ' " & _
",REG_N0 = ' " & Me.Text19 & " ' " & _
"WHERE FLIGHT_NR = " & Me.Text0

flightsubform.Form.Requery

1 个答案:

答案 0 :(得分:0)

Field FLIGHT_NR是整数字段(1,145)还是文本字段(KQ145)?

如果是整数字段,您可能需要更改Where语句以将Me.Text0捕获为整数,如下所示:

" WHERE FLIGHT_NR = " & int(Me.Text0)

如果是文本字段,您可能需要在Me.Text0值周围添加引号以将其捕获为文本:

" WHERE FLIGHT_NR = " & " ' " & Me.Text0 & " ' "

修改
更改代码以进行调试,如下所示:

My_SqlText =  " UPDATE FLIGHT SET " & _
"STD= ' " & Me.Text3 & " ' " & _
",Destination = ' " & Me.Text5 & " ' " & _
",Remark = ' " & Me.Text7 & " ' " & _
",ETD = ' " & Me.Text9 & " ' " & _
",ATD = ' " & Me.Text11 & " ' " & _
",OFBL =  ' " & Me.Text13 & " ' " & _
",CAR= ' " & Me.Text15 & " '  " & _
",Nature = ' " & Me.Text17 & " ' " & _
",REG_N0 = ' " & Me.Text19 & " ' " & _
" WHERE FLIGHT_NR = " & " ' " & Me.Text0 & " ' "
Debug.print My_SqlText 'Will print it to immediate window for inspection
CurrentDb.Execute My_SqlText 
 UPDATE FLIGHT SET STD= ' 4:55:00 PM ' ,Destination = ' ATH ' ,Remark = ' DEP ' ,ETD = '  ' ,ATD = ' 5:15:00 PM ' ,OFBL =  ' 5:05:00 PM ' ,CAR= ' A3 '  ,Nature = ' J ' ,REG_N0 = ' ZA_A309 '  WHERE FLIGHT_NR =  ' A3 847 ' 





 UPDATE FLIGHT SET STD= ' 4:55:00 PM ' ,Destination = ' ATH ' ,Remark = ' DEP ' ,ETD = '  ' ,ATD = ' 5:15:00 PM ' ,OFBL =  ' 5:05:00 PM ' ,CAR= ' A3 '  ,Nature = ' J ' ,REG_N0 = ' ZA_A309 '  WHERE FLIGHT_NR =  ' A3 847 '