Re: DoCmd.GoToRecord , , acNewRec



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




.


Loading