我在表“MTOStudy”和“OtherDesc”中添加了兩個新欄位作為短文本資料型別。表中的其他資料型別是數字和是/否值。
但是,在 Access 中添加兩列并更新表格的相應表單我無法在單擊按鈕后更新表格。
我已經確認的事情:
- 該按鈕使用訊息框功能起作用。
- 變數與表格一致。
- 除了添加“MTOStudy”和“OtherDesc”變數之外,代碼與作業函式相同
- 我看到的錯誤代碼是“錯誤號:3078;MS Access 資料庫引擎找不到輸入表或查詢'128'。確保它存在并且它的名稱拼寫正確。”
除錯行:INSERT INTO tbl_MTO_vs_ETO ([Order], [Line], [MTO], [ETO], [DUP], [MTOStudy], [OtherDesc]) VALUES ( , , -1, 0, 0, "TEST ONE PUMP ", "")
這是下面的功能:
Private Sub btn_save_Click()
'On Error GoTo Err_Execute
If Me.Check_MTO = False And Me.Check_ETO = False And Me.Check_DUP = False Then
MsgBox ("Please select one of the classification options."), vbCritical
Else
Dim Append_SQL As String, tbl_target As String, _
target_fields As String, field_values As String, _
errLoop As Error
tbl_target = "tbl_MTO_vs_ETO"
target_fields = "([Order]," _
& " [Line]," _
& " [MTO]," _
& " [ETO]," _
& " [DUP]," _
& " [MTOStudy]," _
& " [OtherDesc])"
field_values = "(" _
& " " & Me.order & "," _
& " " & Me.line & "," _
& " " & Me.Check_MTO.Value & "," _
& " " & Me.Check_ETO.Value & "," _
& " " & Me.Check_DUP.Value & "," _
& " """ & Me.MTOStudy.Value & """," _
& " """ & Me.OtherDesc.Value & """)"
Call Check_MTO_Dropdown
Append_SQL = "INSERT INTO " & tbl_target & " " & target_fields & " VALUES " & field_values
CurrentDb.Execute Append_SQL
Debug.Print Append_SQL
On Error GoTo 0
Err_Execute:
If DBEngine.Errors.count > 0 Then
For Each errLoop In DBEngine.Errors
MsgBox "Error number: " & errLoop.Number & vbCr & _
errLoop.description
Next errLoop
End If
'DoCmd.Close acForm, Me.name
'MsgBox ("Test"), vbOKOnly
End If
End Sub
uj5u.com熱心網友回復:
正如 HackSlash 提到的,我也更喜歡 Recordsets。
如果你想走那條路,試試這個:
Private Sub btn_save_Click()
'Create new record in tbl_MTO_vs_ETO
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl_MTO_vs_ETO")
With rs
.AddNew
![Order] = Order
![Line] = Line
![MTO] = Check_MTO.Value
![ETO] = Check_ETO.Value
![DUP] = Check_DUP.Value
![MTOStudy] = MTOStudy.Value
![OtherDesc] = OtherDesc.Value
.Update
End With
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
uj5u.com熱心網友回復:
您的陳述句的VALUES子句INSERT將觸發錯誤 3134:“INSERT INTO 陳述句中的語法錯誤”,因為在前兩個逗號之前不包含任何值:
... VALUES ( , , -1, 0, 0, "TEST ONE PUMP", "")
^ ^
您需要為每個列出的欄位提供一些東西。如果前兩個欄位允許Null,您應該能夠避免使用該錯誤:
... VALUES (Null, Null, -1, 0, 0, "TEST ONE PUMP", "")
uj5u.com熱心網友回復:
如果 MTOStudy 或 OtherDesc 中包含引號/撇號字符(" 或 '),除非您從輸入中過濾這些字符或撰寫更多代碼來處理它們,否則這將爆炸。您最好使用記錄集作為 HackSlash 注釋更多。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/439844.html
