473,651 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check for BeforeUpdate success..?

20 New Member
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.Bookm ark line.

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

Thoughts?

Thanks
Oct 5 '07 #1
2 2677
thatguyNYC
20 New Member
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_DblClic k():
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 Recognized Expert Specialist
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
4037
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 to the next record. So, in the BeforeUpdate event of the form itself I have the following code:
4
4059
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 the check box is being checked, some validation is performed. If the validation fails, I set cancel to true, and the check box is not checked afterwards. This is fine.
9
3373
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
14817
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 the combobox I have some code to check the value against some criteria and if the new selected value fails the criteria, I cancel the BeforeUpdate event. I need the combobox to return to its previous value. For example, the current value is MyValue...
6
3121
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 programmer), I finally figured out that the place to put the validations is in Form_BeforeUpdate. I have 2 questions: 1) once I determine there is an error and display a message box with
3
3208
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 some BeforeUpdate field validation code. I would like to do the following:
1
3609
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 actually working. I'm not an HTTP pro, should I expect to see some kind of response after I close the Stream from GetResponseStream()? Any codes I can check for? I have been watching the HasResponse property, but it's always false. Don't know...
9
2845
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 (Array == 'APPLE'){ do something; } or do I need to use a different method to check?
2
4993
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
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8697
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8465
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.