Delete button problem

J

Joan

Hi,
I have a form with several subforms on it. This form and its subforms
are used for editing or deleting data. On one of these subforms, I have a
Delete button for each record in case the user would like to delete that
record from the form. In my code for the OnClick event, I delete the record
and then update a control on the main form that is bound to a field in its
underlying table. The problem is that after the user clicks the delete
button, the record is taken off of the subform but before than user can do
anything else, the main form goes to the first record in it's underlying
table and the rest of the code that updates the main form's !txtDebit does
not run. Why is it doing this?? I cannot figure this out. Would so
appreciate any ideas on why this is happening! Below is my code for the
ClickEvent:


Private Sub cmdDeleteOthChrg_Click()
On Error GoTo Err_cmdDeleteOthChrg_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

With Me.Parent
!txtDebit = ![InvoiceDetailsSubEdit]![ExtendedPriceSum]
.Recalc
End With

Exit_cmdDeleteOthChrg_Click:
Exit Sub

Err_cmdDeleteOthChrg_Click:
MsgBox Err.Description
Resume Exit_cmdDeleteOthChrg_Click

End Sub

Joan
 
J

Joan

I figured out that my form does this when it has been opened by the OpenForm
method without a Where condition argument. When it is opened with a Where
condition argument, the form does not go to the first record but remains
where it is after clicking the Delete button on the subform.

I guess my next question then is how do I code it so that the form will move
back to the Invoice record that I was on when I clicked the Delete button?
I tried the following but it does not work:

Private Sub cmdDeleteOthChrg_Click()
On Error GoTo Err_cmdDeleteOthChrg_Click
Dim Myrs As Object
Dim InvNum As Long
Dim iAns As Integer

InvNum = Forms!EditDeleteInvoice!txtInvoiceNumber

iAns = MsgBox("This will delete " & Me!cboChargeCode & ". OK?", vbYesNo)
If iAns = vbYes Then
DoCmd.RunCommand acCmdDeleteRecord
End If


If Me.FilterOn Then Me.FilterOn = False

Set Myrs = Me.Recordset.Clone
Myrs.MoveFirst
Myrs.FindFirst "CStr([Invoice Number]) =" & "'" & InvNum & "'"
Me.Bookmark = Myrs.Bookmark

With Me.Parent
!txtDebit = ![InvoiceDetailsSubEdit]![ExtendedPriceSum]
.Recalc
End With

Exit_cmdDeleteOthChrg_Click:
Exit Sub

Err_cmdDeleteOthChrg_Click:
MsgBox Err.Description
Resume Exit_cmdDeleteOthChrg_Click

End Sub

Is my syntax right for the following line?
Myrs.FindFirst "CStr([Invoice Number]) =" & "'" & InvNum & "'"

Or maybe there is an easier way of doing 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