By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,105 Members | 2,620 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,105 IT Pros & Developers. It's quick & easy.

Check for BeforeUpdate success..?

P: 20

I have a form that lets the user edit the values in a lookup table. The form is bound to a table and has one textbox on it. The record nav buttons are enabled. On the top half of the form, I have a listbox showing all the records in the table. The user can double-click the listbox to jump to that record via this code:
Expand|Select|Wrap|Line Numbers
  1.     Me.RecordsetClone.FindFirst "[cSalut] = '" & Trim(Nz(Me.lstSaluts)) & "'"
  2. If Not Me.RecordsetClone.EOF Then Me.Bookmark = Me.RecordsetClone.Bookmark
  3. Me.txtSalut.SetFocus
In the form's BeforeUpdate event, I check to see that the new textbox value isn't blank and isn't already in the table
Expand|Select|Wrap|Line Numbers
  1.     ' prevent user from changing value to one already in the list
  2. If DCount("[cSalut]", "[Saluts]", "[cSalut] = '" & Trim$(Nz(Me.txtSalut)) & "'") > 0 Then
  3.    MsgBox "That Salutation already exists."
  4.    Cancel = -1
  5. End If
  7.     ' prevent a blank record
  8. If Len(Trim$(Nz(Me.txtSalut))) = 0 Then
  9.    MsgBox "The Salutation field cannot be blank."
  10.    Cancel = -1
  11. End If
The problem occurs in this way:
- The user edits a record by clearing the textbox;
- The user then double-clicks the listbox
- The BeforeUpdate fires, but the textbox is blank so it gets cancelled
- However, the DblClick code still finishes and I get a No Current Record error on the Recordset.Bookmark line.

So I'm wondering if there's any way to tell whether or not BeforeUpdate failed.


Oct 5 '07 #1
Share this Question
Share on Google+
2 Replies

P: 20
Well, I've come up with a semi-solution.. For the time being, until something better comes along, I've got this in the listbox_DblClick():
Expand|Select|Wrap|Line Numbers
  1. If Me.Dirty Then
  2.    MsgBox "Please save your changes before double-clicking this listbox."
  3. Else
  4.    ' move the recordpointer...
  5. End If
And in the BeforeUpdate I have both data checks.

It's not the greatest, but it works.

Oct 5 '07 #2

Expert 2.5K+
P: 3,072
I never rely on the BeforeUpdate event. It can be done, but you'll need to cancel the event when the entered data is invalid.
I always use two "standard" windows buttons [Cancel] and [Save].
Cancel does close the form without leaving "traces" and the Save button will hold the validation and only add/update when all's OK.

Getting the idea ?

Oct 6 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.