Delete button

J

Joan

Hi,

Am having problems passing variable values to query parameters.
I have subform on an InvoiceForm in which the default view is continuous
forms and the DataEntry property is set to false. For each record on the
subform, I have a delete button where the user can delete the record off of
the form however the info pertaining to this record is still in the tables.
The status of the record just changed from being sold to being in
inventory. The code behind the button is the button wizard's DoMenuItem
code:
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, ,acMenuVer70


I would also like to run an update query on other fields for this record
with the ClickEvent of this Delete button. These fields do not have
controls on the subform , but are in the subform's record source. I'd like
to store the
values of 3 controls in variables and then pass these values to the query's
parameters
after I delete the record. I've tried to do this in the code below but the
update query
does not update the record. Would someone mind taking a look at my code to
see
what I am doing wrong? I declared my parameters and types in the query
design. The
update query seems to work if I run it manually.

Private Sub cmdDeleteDog_Click()
On Error GoTo Err_cmdDeleteDog_Click
Dim stDog As Long
Dim stReturned As String
Dim dtDate As Date
Dim db As Database
Dim qdf As QueryDef
Dim prm As Parameter

'Assign current database to database variable
Set db = CurrentDb

Set qdf = db.QueryDefs("qryUpdateRetDogCancel")
' Assign control values to variables
stDog = Me.Dog_Number
stReturned = Me.Returned
dtDate = Forms!EditDeleteInvoice!dteDate

' Delete record on subform
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Me.Recalc
Forms![EditDeleteInvoice]![AddDogtoInv].Requery
' If the dog that is being deleted was a resale of a returned dog then
If stReturned = "Y" Then
' With qdf, pass variable values to query parameters and then execute
With qdf
.Parameters("DogNum") = stDog
.Parameters("Return") = stReturned
.Parameters("SellDate") = dtDate
.Execute dbFailOnError
End With
End If

Exit_cmdDeleteDog_Click:
Exit Sub

Err_cmdDeleteDog_Click:
MsgBox Err.Description
Resume Exit_cmdDeleteDog_Click

End Sub

Thanks ahead for any help with this.

Joan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top