Code to prohibit runtime error 2105

G

Guest

My form includes a text box with Company names in it and two command buttons:
1. Add new name 2. Save data and close. All possible errors are covered
except when the user presses "Add new name", begins typing in a name and
presses "Add new name" again. The Run Time Error #2105 appears. What code
can be used in addition to a message to prohibit a user from making the
mistake of pressing the "Add new name" two times?

cmdAdd cmdSave
 
A

Allen Browne

It might help to know what code is in the event procedure, but I'm guessing
the message means you cannot go to a new record because you are already at a
new record.

This kind of checking should prevent the problem:

Private Sub cmdAdd_Click()
If Not Me.NewRecord Then
If Me.Dirty Then
RunCommand acCmdSaveRecord
End If
RunCommand acCmdRecordsGoToNew
End If
End Sub
 
M

MacDermott

The code you use would depend on what effect you want to achieve.
If you want to let your users move on to another record when they're already
working on a new one, Allen Browne's code will work fine.
If you want to keep your users from pressing the AddNew button while
entering a new record, one approach would be to check in the form's Current
event, something like this:
cmdAdd.Enabled=(Me.NewRecord=false)
This will disable the Add button (cmdAdd) if you're on a new record, and
enable it if you're not.
The downside to this approach is that you're not giving your users any
explanation of what's going on.

HTH
 

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