Connecting Tech Pros Worldwide Help | Site Map

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

Newbie
 
Join Date: May 2007
Posts: 9
#1: May 29 '07
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
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,865
#2: Jun 1 '07

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


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
Newbie
 
Join Date: May 2007
Posts: 9
#3: Jun 2 '07

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


Quote:

Originally Posted by mmccarthy

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.
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,865
#4: Jun 2 '07

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


Quote:

Originally Posted by kiwipedia

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.
maxamis4's Avatar
Expert
 
Join Date: Jan 2007
Location: Northern VA
Posts: 214
#5: Jun 2 '07

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


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
Newbie
 
Join Date: May 2007
Posts: 9
#6: Jun 5 '07

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


Quote:

Originally Posted by mmccarthy

... 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.
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,865
#7: Jun 5 '07

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


Glad you got it working Michael.
Reply