Bypass code

T

Tara

I have a piece of code that is set to execute On Exit of a field (Balance).
When I delete a record, I have code that sets the focus to the Balance field
on the previous record. If the focus is placed in the Balance field due to a
deletion, I want to bypass the code that would normally run when the Balance
field is exited. Can this be done? I thought maybe by coding the delete
button correctly I could over-ride the code in the Balance field, but I
haven't had any luck so far.

Thanks for any input!
 
T

Tara

I have code in both the On Enter and On Exit events of the Balance field that
influence the outcome I need, so I'll post both sets of code. I'll also post
the code I have in the delete button. It also influences the outcome...It
doesn't work quite the way I want it to, but it helps illustrate what I want
to do.

Here's the On Exit code:

Private Sub Balance_Exit(Cancel As Integer)
If MsgBox("Do you want to add another record?", vbExclamation + vbYesNo)
= vbYes Then
ClaimDate.SetFocus
DoCmd.GoToRecord , , acNewRec
Else
PayOut.SetFocus

End If

End Sub

Here's the On Enter code:

Private Sub Balance_Enter()
Balance = StartingAmt - PayOut

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Forms!frmEmpAcct!Balance = Me.Balance

And here's the code in the Delete button:

Private Sub DelReceipt_Click()
On Error GoTo Err_DelReceipt_Click

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

DoCmd.GoToRecord , , acPrevious
Remaining.SetFocus

Exit_DelReceipt_Click:
Exit Sub

Err_DelReceipt_Click:
MsgBox Err.Description
Resume Exit_DelReceipt_Click

End Sub
 
A

Arvin Meyer [MVP]

If ... Then ... Else statements will usually branch code. Post your code so
that we can see what you have done.
 
T

Tara

The code in the Delete button says Remaining.SetFocus. It should say
Balance.SetFocus. I changed the field name, copied the code from the delete
button to try something else, and ended up rebuilding the delete button
again, without changing the code to reflect the field name change. Just
wanted to clarify that so as to avoid any confusion.
 
T

Tara

I need to find an easy way for the user to create a new record (or choose not
to)after they complete the record they are in, so coding it for a custom
message box seemed the easiest way to do that. I understand that it fires
each time, which is a drawback, I agree. That's why I wanted to know if
there was any work around to avoid having it fire under other circumstances.
 

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