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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,215,373
Messages
6,124,562
Members
449,171
Latest member
jominadeo

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