Re: DoCmd.GoToRecord , , acNewRec



Are the "add" and "cancel" buttons in the same section of the main form?

Is the "grpCountry" control bound to a field in the form's RecordSource?
What is the code that runs on the AfterUpdate event for the "grpCountry"
control? I don't see any "Me.Undo" code step in the cancel button's code?

Your description of what works and what doesn't work suggests that an error
is occurring in the Cancel button when you click it during the second cycle.
I see you have an error handler in that code; does it get called at all
during your sequence? What is the code for the Handle_Err subroutine?

I have found that uncleared errors from a called function or subroutine can
cause an error for the calling code that does not trip the calling code's
error handler, and the code silently fails. This may be what you're seeing
as well.

Another source of a silent failure has been that code on another control
raises an error that prevents the code from continuing -- e.g., trying to
change the value of a control during its BeforeUpdate event, trying to
change the focus from a control and code in its LostFocus or Exit event
fails, trying to change focus to a control and code in its GotFocus or Enter
event fails, etc.

So, it may be necessary for you to post all the code in the form's module
and the external subs/functions that are called. Let's see what's being
done.
--

Ken Snell
<MS ACCESS MVP>



"Rick Allison" <allisonrja@xxxxxxxxxxx> wrote in message
news:%23w03UcSaGHA.3328@xxxxxxxxxxxxxxxxxxxxxxx
Ken,

The form is bound to a query and is a single form with subforms. However,
when adding a new record focus is set to the first textbox on the main
form,
never switching to the subform.

What's strange is this. If I click the add button then cancel then close
the form nothing is added. However, if I click the add button, the cancel
button, the add button, the cancel button, close the form, and open the
form, one blank row is added to the database. Go figure. I guess that's
why I'm pulling my hair out. I guess the user will probably never do this
but all it takes is once and I'll be asked to fix it. Why does it do
this?

Here's the add owner code:

Private Sub cmdAddOwner_Click()
On Error GoTo HandleError

EnableControls Me, acDetail, True
Select Case ObtainOrganization
Case "CKC"
Me!grpCountry = 1
Case "AKC"
Me!grpCountry = 2
End Select
Call grpCountry_AfterUpdate
Me!cmdApply.Enabled = True
Me.cmdCancel.Enabled = True
Me!cboSelectOwner.Enabled = False
Me!cmdDogEntry.Enabled = False
Me!cmdEditDog.Enabled = False
Me!cmdDeleteThisOwner.Enabled = False
Me!cmdAgilityEntryForm.Enabled = False
Me!cmdAddDog.Enabled = False
Me!btnMailingLabel.Enabled = False
Me!cmdDeleteSelectedDog.Enabled = False
Me!fsubOwnerLastEntered.Enabled = False
Me!fsubDogList.Enabled = False
DoCmd.GoToRecord , , acNewRec
Me!txtActualOwnerFirstName.SetFocus
Me!cmdAddOwner.Enabled = False
blnAddOwner = True

ExitHere:
Exit Sub

HandleError:
Select Case Err.Number
Case 2448
Resume Next
Case Else
Call Handle_Err(Err.Number, Err.Description,
"OwnerMaintenance-cmdAddOwner_Click")
Resume ExitHere
End Select
End Sub

Here's the cancel code:

Private Sub cmdCancel_Click()
Dim strAddUpdate As String

On Error GoTo HandleError
EnableControls Me, acDetail, False
Me!cboSelectOwner.Enabled = True
Me!cmdAddOwner.Enabled = True
Me!cboSelectOwner.Enabled = True
Me!cboSelectOwner.SetFocus
Me!cmdApply.Enabled = False
Me!cmdCancel.Enabled = False

ExitHere:
Exit Sub
HandleError:
Call Handle_Err(Err.Number, Err.Description,
"OwnerMaintenance-cmdCancel_Click")
Resume ExitHere
End Sub

I've tired using me.undo and me.dirty. If I click add then cancel
me.dirty
is not set. If I check for null values in key fields I can trip the
me.undo
but that does not seem to work.


--
Rick Allison
"Ken Snell (MVP)" <kthsneisllis9@xxxxxxxxxxxxxxxxxx> wrote in message
news:eNxWULNaGHA.3444@xxxxxxxxxxxxxxxxxxxxxxx
Tell us more about the form's setup and record source. If no data are
entered by the user or by programming, then a Me.Undo action should avoid
the saving of the new record.

However, if you're using a subform in the form, and the focus moves from
the
form in which you've added the new record to the "other" form (main form
or
subform), then the newly added record will be saved as part of the focus
move.
--

Ken Snell
<MS ACCESS MVP>


"Rick A" <allisonrja@xxxxxxxxxxx> wrote in message
news:eLTGHTLaGHA.428@xxxxxxxxxxxxxxxxxxxxxxx
I have a button on a bound form that adds a new record. It runs the
code -
DoCmd.GoToRecord , , acNewRec

I also have a cancel button in case the person changes their mind. In
testing I press the Add button and then the Cancel button and a new blank
record is added. I want to stop this behavior.

I've tried if me.dirty but since nothing has been typed on the form it's
not
dirty. I've tried me.undo but that's not working either.

How do I trap for this and stop the insert of a blank row into the
database?

Thanks,

--
Rick






.