Making Bound Controls to stop insert inputs to the bound table

webcrab

Registered User.
Local time
Today, 12:42
Joined
Feb 18, 2009
Messages
36
Hi!
I have a form that contains bound textboxes to a table and "add record" button that subbmitting all the textboxes.text into the table.

My problem is: every time i insert simple text in one of the text boxes by mistake the text is submitted to the form without clicking the "Add record" button and creates a new record in the table.

How Can I stop this kind of behaviour at the bound textboxes?

Thanx a Lot guys!
 
In the before update event you can test to see if the 'Add' button has focus and if it does not cancel the before update event - ?
 
And How do i write that in vba?
 
You're trying to reinvent the way Access is intended to work, and this becomes a problem with experienced Access data input users. They know that Access saves records when moving to another record or when the form is closed, and expect this behavior. In my opinion, it's a better policy to allow Access to work in its native way and merely check with the user before the record is saved, allowing them to save it or dump the new record or changes. This piece of code will do just that

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not (Me.NewRecord) Then
 If MsgBox("Would You Like To Save The Changes To This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save Changes to Record ???") = vbNo Then
  Me.Undo
 End If
Else
 If MsgBox("Would You Like To Save This New Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This Record ???") = vbNo Then
  Me.Undo
 End If
End If
End Sub

You can still add a "Save" button, if some users expect it, merely having it set up to move to a new record. The users will still be asked to confirm the save, from the code above, but experienced Access users can run the app the way they know it's intended to work.
 

Users who are viewing this thread

Back
Top Bottom