using QueryDef and SQL DELETE

ckib

Board Regular
Joined
Sep 14, 2005
Messages
219
Hi, I'm attempting to delete a record from table tblSegment when the value of a field on a form is set to "N". I think there is a problem with my strSQL, I get the error: Run time error '91': Object variable or With block variable not set. Thanks for any help you can provide.

Here is my code:

If Me!List_active_status.Value = "N" And Not IsNull(Me!cont_projectID) Then
strText = "Are you sure you want to remove this contact from the project?"
theAns = MsgBox(strText, vbOKCancel)

If theAns = 2 Then 'response = cancel ... abort process
Undo
Else 'response = Okay
'remove this project/contact from tblSegment
Dim myDeleteQry As QueryDef, myDeleteRS As Recordset

' Define SQL statement for delete query

strSQL = "DELETE tblSegment.seg_projectID, tblSegment.seg_contactID, tblSegment.seg_num ) " & _
"FROM tblSegment " & _
"WHERE (((tblSegment.seg_projectID)='" & strProjectID & "')" & _
"AND ((tblSegment.seg_contactID)='" & strContactID & "'));"

Set myDeleteQry = myDB.CreateQueryDef("", strSQL) ' create temp delete query

' Run temporary QueryDef

myDeleteQry.Execute
myDeleteQry.Close

End If
End If
 
Take a look at the SetWarnings method.
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,224,894
Messages
6,181,618
Members
453,057
Latest member
LE102024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top