I am currently stuck on a problem and could use a little help. I am trying to run a delete query using the current selection as the parameter. I feel like I am close but I keep erroring out. Here is my code:
Sub doSomething()
Dim accessID As Integer
Dim firstName As String
Dim lastName As String
Dim custID As String
With ActiveCell
accessID = Range(Cells(.Row, "A"), Cells(.Row, "A"))
firstName = Range(Cells(.Row, "F"), Cells(.Row, "F"))
lastName = Range(Cells(.Row, "E"), Cells(.Row, "E"))
custID = Range(Cells(.Row, "G"), Cells(.Row, "G"))
End With
If MsgBox("Please confirm you are wanting to delete:" & vbCrLf & vbCrLf & firstName & " " & lastName & " - " & custID, vbYesNo, "CONFIRM") = vbNo Then
'Do Nothing
Else
Dim MyDatabase As DAO.Database
Dim MyQueryDef As DAO.QueryDef
Dim MyRecordset As DAO.Recordset
Dim i As Integer
Application.ScreenUpdating = False
Set MyDatabase = DBEngine.OpenDatabase("\\Acsetdata02\shared\Holland\Craig\WMWExits\WMWExits\bin\Release\Exits.accdb")
Set MyQueryDef = MyDatabase.QueryDefs("qry_ExitsDelete")
With MyQueryDef
.Parameters("[ID_?]") = accessID
End With
MyQueryDef.Execute
ActiveCell.EntireRow.Delete
Set MyDatabase = Nothing
Set MyQueryDef = Nothing
Application.ScreenUpdating = True
MsgBox "Data has been successfully imported!"
End If
End Sub
It is erroring on "MyQueryDef.Execute" and stating "Run-time error 3464 : Data type mismatch in criteria expression"
I am new to writing VBA that crosses between Excel and Access. Any help on this would be greatly appreciated!!!
Bookmarks