我有這個 VBA 代碼,可以在 Microsoft Access 資料庫中保存和編輯許多資訊。
在一個 sub 中,我需要使用 AND 運算子過濾我的記錄集。
我現在有這個:
rst.Filter = "OT ='" & oot & "'"
rst.Filter = "Parcial ='" & PARCIAL & "'"
rst.Delete
我想把它變成這樣的:
rst.Filter = "OT ='" & oot & "'" AND "Parcial ='" & PARCIAL & "'"
rst.Delete
這是整個子:
Sub delete_ot()
ThisWorkbook.Activate
Dim cnn As ADODB.Connection 'dim the ADO collection class
Dim rst As ADODB.Recordset 'dim the ADO recordset class
Dim dbPath
Dim x As Long, i As Long
Dim nextrow As Long
Dim wsc As Worksheet
Dim wb As Workbook
Dim oot As String
Dim PARCIAL As String
PARCIAL = Corte.PARCIAL
oot = CStr(Corte.TextBox16)
On Error GoTo errHandler:
Set wb = ThisWorkbook
Set wsc = wb.Worksheets("Auxiliar")
Dim folderPath As String
folderPath = Application.ActiveWorkbook.Path
Dim pasta As String
pasta = folderPath & "\" & wsc.Range("J2").Value
dbPath = pasta & "\" & wsc.Range("J4").Value & ".accdb"
'Initialise the collection class variable
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath
Set rst = New ADODB.Recordset
'ConnectionString Open '—-5 aguments—-
'Source, ActiveConnection, CursorType, LockType, Options
rst.Open Source:="Registro_corte", ActiveConnection:=cnn, _
CursorType:=adOpenDynamic, LockType:=adLockOptimistic, _
Options:=adCmdTable
rst.Filter = "OT ='" & oot & "'"
rst.Filter = "Parcial ='" & PARCIAL & "'"
rst.Delete
'close the recordset
rst.Close
' Close the connection
cnn.Close
'clear memory
Set rst = Nothing
Set cnn = Nothing
On Error GoTo 0
Exit Sub
errHandler:
'Clear memory
Set rst = Nothing
Set cnn = Nothing
MsgBox "Error FAVOR AVISAR ENGENHARIA " & err.Number & " (" & err.Description & ") in procedure Delete_OT"
End Sub
任何幫助將不勝感激
uj5u.com熱心網友回復:
AND 成為過濾器字串的一部分:
rst.Filter = "OT ='" & oot & "' AND Parcial ='" & PARCIAL & "'"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/364365.html
上一篇:如何在1中合并2個表并在合并前將第二個表中的值更改為負值
下一篇:VBA訪問-測量顯示單位
