By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,795 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,795 IT Pros & Developers. It's quick & easy.

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

P: 9
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
Share this Question
Share on Google+
6 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
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

P: 9
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
Expert Mod 10K+
P: 14,534
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
Expert 100+
P: 295
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

P: 9
... 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
Expert Mod 10K+
P: 14,534
Glad you got it working Michael.
Jun 5 '07 #7

Post your reply

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