473,836 Members | 1,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Required field / error with null value / can't move focus

9 New Member
Hi all

I have a combo-box control [Insertion] which I've set as a required field. It's a date and uses a calendar as coded below. All works fine unless the user deletes a pre-existing value (leaving a 0-length string I guess) and then clicks in the Insertion control.

This results in Runtime error '2110' with the message that "can't move the focus to the control Calendar0"

I think this is because I've made Insertion a required field - certainly the problem is "resolved" if I make Insertion not required.

But I do want it to be a required field...any ideas? I did try loading a default value (today's date) into the field after MouseDown if the value was null or zero length string but that didn't work and anyway I don't like the idea of deliberately putting a false value into the field.
Access 2003, Windows XP

Expand|Select|Wrap|Line Numbers
  1. Private Sub Insertion_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2. Calendar0.Visible = True
  3. Calendar0.SetFocus
  4. If Not IsNull(Insertion) Then
  5.     Calendar0.Value = Insertion.Value
  6. Else
  7.     Calendar0.Value = Date
  8.  
  9. End If
  10. End Sub
  11. Private Sub Calendar0_Click()
  12. If Calendar0.Value > Date Then
  13. MsgBox "Insertion Date cannot be in the future."
  14.             Calendar0.SetFocus
  15.             Calendar0.Value = Date
  16. ElseIf Calendar0.Value < Me.Parent.DOB Then
  17.     Call MsgBox("Insertion Date cannot Precede Date of Birth", , "NICU Line Infection Database")
  18.             Calendar0.SetFocus
  19.             Calendar0.Value = Me.Parent.DOB
  20.   Else
  21.   Insertion.Value = Calendar0.Value
  22.   Insertion.SetFocus
  23. Calendar0.Visible = False
  24. End If
  25. End Sub
  26.  
Thanks - Michael
May 29 '07 #1
7 8082
MMcCarthy
14,534 Recognized Expert Moderator MVP
Hi Michael,

Don't set the field to required, just make it so they can't save the record unless the date if entered.

Mary
Jun 1 '07 #2
kiwipedia
9 New Member
Hi Michael,

Don't set the field to required, just make it so they can't save the record unless the date if entered.

Mary
You are messing with my mind!

Michael.
Jun 1 '07 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
You are messing with my mind!

Michael.

... unless the date is entered. sorry.

Just check for the date in the save/close event or maybe in the current event whichever is more suitable. In other words if they try to add a record without entering a date you can popup a message box saying please enter date to proceed.
Jun 1 '07 #4
maxamis4
295 Recognized Expert Contributor
I don't see why you don't set the code in the after update event of the combo box. What this means is that after the combo box is updated, it will return the value you want.


I can't follow your code because you don't use typical programming conventions. I don't mean to be rude just trying to help you out. Could repost the variable with labels so I can assist you with this.

example:

variable1 = my combo box
variable2 = my text box
variable3 = my button

thanks
Jun 2 '07 #5
kiwipedia
9 New Member
... unless the date is entered. sorry.

Just check for the date in the save/close event or maybe in the current event whichever is more suitable. In other words if they try to add a record without entering a date you can popup a message box saying please enter date to proceed.

Thanks - I tried that idea using a few different events - in the end the unload event of the Parent form seemed to be best:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel As Integer)
  2.     If IsNull(Forms!frmentry.subfrmlines![Insertion].Value) Then
  3.     MsgBox ("Please Enter the Line Insertion Date")
  4.     Cancel = True
  5.     Me!subfrmlines.SetFocus
  6. Me!subfrmlines.Form!Calendar0.Visible = True
  7. Me!subfrmlines.Form!Calendar0.SetFocus
  8. Me!subfrmlines.Form!Calendar0.Value = Date
  9.     End If
  10. End Sub
  11.  
Cheers - Michael.
Jun 5 '07 #6
MMcCarthy
14,534 Recognized Expert Moderator MVP
Glad you got it working Michael.
Jun 5 '07 #7
jordimarsa
2 New Member
First of all, I prefer always using before or after update events in order to tirgger them always. The mouse events can be avoided by using the keyboard instead.

Secondly, I think that there is a missunderstandi ng on how to change values in a form. You do not really need to set focus on another control you can just change the value property.

Finally, about the error, you can do several things taking into account that you are using a required field. If the field is required and it has been already filled you cannot change it by a null value. The only way to have a null value in a required field is before inserting a record and before attempting to change it.

A good way to avoid the error is by using the BeforeUpdate event and if the value is null use the method "Me.[Insertion].Undo" to retake the last value introduced. But a required field means exactly that you cannot save the record without a value. It's in your hand which value you prefer to leave if the user decide to do something forbiden. In datasheet mode I tend to show the error and set the focus to the field that has been missed, but you can undo the change or even set another value more suitable like the current date. If you want to do something particular, please explain me how is your form and what exactly you expect it to behave for the user and I will try to help you.
Sep 28 '21 #8

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

Similar topics

2
14304
by: fish | last post by:
Hi, I have an HTML page with a FORM and some input fields. On the fields I wish to do validation as the punters change the field values. If they get it wrong, then I tell them and then wish to put the focus back to the offending field. ( It works if a use an 'onblur' event but not an 'onchange' )
2
3280
by: SAN CAZIANO | last post by:
check required in a select how can i control if a combobox (a select) is not null (index is -1) or if index is 0 if the first element is for example a null value or simply a description of the field . I try to use this if (combobox.SelectedIndex==0 || combobox.SelectedIndex==-1)
1
3776
by: IkBenHet | last post by:
Hello, I found this script to create a simple rich text form (http://programmabilities.com/xml/index.php?id=17): <html> <head> <title>Rich Text Editor</title> </head> <body>
16
8497
by: Georges Heinesch | last post by:
Hi. My form contains a control (cboFooBar), which has an underlying field with the "Required" property set to "Yes". Now, while filling out all the controls of the form, I have to fill out this particular (required) control as well. However further down the form, there is another control, which has to (under certain conditions) to delete again the content of the (required) control just filled out before (cboFooBar). This is done by...
5
5637
by: Dave Brydon | last post by:
I'm checking for required fields, and using the code below, which I normally have no difficulties with; however, as a twist I decided to return the focus back to the specific field(s) in question for input. Under the "Case vbYes" I indicated the two required fields to return the focus, based on which one is empty, however, I cannot seem to return the focus. If I only have one field indicated in the code, example; If Me.txtUDateStart =...
25
10283
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the data in each record, which includes the ID of the father and the mother (who also have records in the table). One record per form. I have a Tab Control in the form, and in one of the tabs I have a subform (sfmSiblings) in which I wish to list...
2
39125
by: bufbec1 | last post by:
I am pretty good with Access, but do not understand VBA. I have researched this topic and see only VBA answers, so I hope someone can help with my specific question. I have 2 fields for an end-user that must be filled in. I want an error message for each field. The forms are already partially filled in, and a user needs to select which record to go to. There are fields for them to fill in their initials and date , along with other...
7
2379
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has finished. I am trying to follow this example : http://www.codeproject.com/cs/miscctrl/progressdialog.asp But although the messages still get moved, the progress window never does anything. Here is my code in full, if anybody who knows...
0
9813
marktang
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...
0
10539
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
10584
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,...
0
9367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7782
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
6976
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();...
0
5645
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...
0
5815
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.