473,395 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Check for BeforeUpdate success..?

Hello--

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
  6.  
  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.

Thoughts?

Thanks
Oct 5 '07 #1
2 2645
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.

Thanks.
Oct 5 '07 #2
nico5038
3,080 Expert 2GB
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 ?

Nic;o)
Oct 6 '07 #3

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

Similar topics

4
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a form with multiple pages on it. There is one text field on the third page of the form that I need the user to complete before leaving the form or moving...
4
by: welie | last post by:
I have a problem canceling a check box update when placing a check in it. Checkbox is not bound. Here is what happens. User clicks a check box. In the BeforeUpdate method of the control, if...
9
by: simonmarkjones | last post by:
I want to call a function which does this when the next record button is pressed (calling it from before update) if textboxes are empty then Message box you must fill text box
2
by: PC Datasheet | last post by:
In a form/subform I have an unbound combobox in the form header that sets the value of a field in the subform so that it does not have to be entered for each record. In the BeforeUpdate event of...
6
by: lorirobn | last post by:
Hi, I have a form with a continuous subform. I am working on putting validations in for the subform's required fields. Being somewhat new to Access (or rather, an antiquated mainframe...
3
by: tlyczko | last post by:
Hello, I think what I'm asking for may not be possible, but I'll try anyway. I have MainForm with 3 subforms, one SubForm requires data entry, the other two don't (optional). MainForm has...
1
by: Steve | last post by:
Hi all, I'm using the HttpWebRequest class to POST a form to a partner site. Communication with the "Partner" site admin is shoddy at best and I'm having a hard time determining if the POST is...
9
by: chutsu | last post by:
hi I got a simple program, and I was wondering how do you check if the string in an array = a string. For example if I put "APPLE" in array Array then how can I check it with a if statement. if...
2
by: stmfc | last post by:
how can i check the success of open function for ifstream class? see the code below: ifstream fin; fin.open("myfile.dat");
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.