473,726 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check for BeforeUpdate success..?

20 New Member

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

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


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

Oct 5 '07 #2
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 ?

Oct 6 '07 #3

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

Similar topics

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:
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.
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
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...
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
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:
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...
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?
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");
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
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,...
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...
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...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.