Is this a timing issue?

G

glen.welsh

I am trying to keep a database from creating new records when the
"next" button is activated at the end of records. I have written the
following code to deactivate the "next" and "last" buttons when the
last record is found. It works, but if I click the next button too
fast, it deactivates before reaching the last record. Any suggestions
are welcome and appreciated.


Private Sub cmdNext_Click()
On Error GoTo Err_Command283_Click


If Me.CurrentRecord >= counter.VALUE - 1 Then
Me.cmdPrevious.Enabled = True
Me.cmdPrevious.SetFocus
Me.cmdFirst.Enabled = True
Me.cmdNew.Enabled = True
Me.cmdNext.Enabled = False
Me.cmdLast.Enabled = False
Else
Me.cmdPrevious.Enabled = True
Me.cmdFirst.Enabled = True
Me.cmdNew.Enabled = True
Me.cmdNext.Enabled = True
Me.cmdLast.Enabled = True


End If
DoCmd.GoToRecord , , acNext


Exit_Command283_Click:
Exit Sub


Err_Command283_Click:
MsgBox Err.Description
Resume Exit_Command283_Click


End Sub
 
T

TC

To keep a /form/ from creating new records, you just set the form's
AllowAdditions property to False. No code is required at all.

HTH,
TC
 
G

glen.welsh

Thanks TC.

The database still needs to have the add capability. I just don't want
the new additions to be added by activating the "next" button when
scrolling through pages.
 
T

tina

set AllowAdditions to No, as TC said. then in the code for your command
button (or whatever you're using to allow the user to add a new record), add
code to set the property back to Yes, before navigating to a NewRecord. such
as

Me.AllowAdditions = True
DoCmd.RunCommand acCmdRecordsGoToNew

then add the following code to the form's AfterUpdate event, to change the
property back to No after the new record is saved (unless you want the user
to add records freely, once s/he begins to), as

If Me.AllowAdditions Then Me.AllowAdditions = False

hth
 
R

Rick Brandt

Thanks TC.

The database still needs to have the add capability. I just don't
want the new additions to be added by activating the "next" button
when scrolling through pages.

Setting AllowAdditions to No will accomplish this. You can then provide your
own "Add" button and it can have code to set AllowAdditions back to Yes and then
take the user to the NewRecord position. In the BeforeInsert event have code
that changes AllowAdditions back to No.
 

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

Similar Threads


Top