469,290 Members | 1,838 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

How to replace "the value you entered isn't valid" with a custom message

137 100+
Is it possible to stop this message from appearing?

I've got a couple of unbound textboxes that I want to use as filters for start date/end date type parameters. I wanted to use the build-in calendar option to let users select a date (as well as being able to type it in) so I set the format of the text boxes to Short Date. However in doing this it means that this "invalid value" message now pops up when the date format is wrong, as opposed to the LostFocus event I had to check the date format and alert the user.

Any idea if it's possible to hide/disable these kinds of messages? Would it be in a similar way to DoCmd.SetWarnings False/True?

Thanks.

Adam.
Jul 5 '11 #1
18 14387
NeoPa
32,173 Expert Mod 16PB
You could check out Custom Error Messages, but I don't think this is your best approach. As what you require is a little unusual you can expect to use a fiddly solution. Mine would be to clear any format of the TextBox control on Entry (the event), and determine it again After Update (event) by the value entered. That way you wouldn't be constrained by the Format while entering data.
Jul 5 '11 #2
pod
298 100+
Jeez Neo, you're quick on the draw :)



Adam if you want to go the "Custom Error Message" way then catch the error number and display a custom message in relation to that number

Expand|Select|Wrap|Line Numbers
  1. Private Sub somefunction()
  2.     On Error GoTo errorCatching
  3.  
  4.     '...some code
  5.  
  6. errorCatching:
  7.     msgbox Err.Number
  8.     ' you will have to determine what number 
  9.     ' comes up as you enter some wrong data 
  10.     ' for testing purposes 
  11.  
  12.     If Err.Number = 2421 Then 
  13.         MsgBox ("please enter an appropriate date")
  14.     End If
  15. End Sub
  16.  
  17.  
  18.  
Jul 5 '11 #3
Adam Tippelt
137 100+
Mmm yeah I don't think that approach would work - that seems to be based around using the run time error codes, whereas this doesn't have one.
The reason I used format was because it seems to be the cleanest way to get a calendar for the text boxes, unless there's another way? (aside from building a calendar form)
Jul 5 '11 #4
pod
298 100+
best for me is to force users to select a date from the control, no more formatting problem
Jul 5 '11 #5
Adam Tippelt
137 100+
pod
have you tried catching the error number and then displaying a custom message in relation to that number
All my procedures already use error trapping. However this is not an 'error' in the sense that the coding is triggering a run time problem with a code. It's caused by the data inputted, not the design, and shows just a standard messagebox with an OK button, just informing the user that the value isn't valid.
Jul 5 '11 #6
Adam Tippelt
137 100+
Mmm the control-only idea could work, but how could I restrict access and still have the calendar functional? Locking the textbox stops user from editing it themselves, but it also stops the calendar from updating the value. And obviously setting the Enabled value to no will stop the users from entering the field at all, which means the calendar won't appear.
Jul 5 '11 #7
pod
298 100+
no need to lock ...you could set the onClick textbox event to show the calendar and set the focus to it. Then after the user clicks a date, you set that value to the textbox
...with a bit more code to make it work

I hope this helps

Expand|Select|Wrap|Line Numbers
  1. Private Sub Calendar2_Click()
  2.    Text0.Value = Calendar2.Value
  3.    Text0.SetFocus
  4.    Calendar2.Visible = False
  5. End Sub
  6.  
  7. Private Sub Text0_Click()
  8.    Calendar2.Visible = True
  9.    Calendar2.SetFocus
  10. End Sub
Jul 5 '11 #8
NeoPa
32,173 Expert Mod 16PB
OnClick assumes the operator will always use the mouse. Try OnEnter instead for more reliably working code.

PS. Was the (main) idea (Event procedures to clear the Format property when entering data into the control) in post #2 missed? I don't see any response to it and was wondering why it might not be appropriate.
Jul 5 '11 #9
NeoPa
32,173 Expert Mod 16PB
Adam Tippelt:
However this is not an 'error' in the sense that the coding is triggering a run time problem with a code. It's caused by the data input
Although I still think this approach limited and am not recommending it, I do believe that ADezii's article on error message substitution may well work in this scenario too (as well as for the more usual code error messages).
Jul 5 '11 #10
Adam Tippelt
137 100+
Although I still think this approach limited and am not recommending it, I do believe that ADezii's article on error message substitution may well work in this scenario too (as well as for the more usual code error messages).
Doesn't ADezii's article work on the basis that the error has a run time code that you use to distinguish what should be done for each error? As the 'error' I have doesn't have a code, surely this wouldn't work? (Unless it has a code but doesn't display it?)

PS. Was the (main) idea (Event procedures to clear the Format property when entering data into the control) in post #2 missed?
Yes...yes it was. :)
I think I completely misread that post - I thought you were talking about removing the Format option completely, but you're talking about temporarily.

Huh...that might be suitable...I'll investigate that and say if it works. :)

Thanks.

Adam.
Jul 5 '11 #11
Adam Tippelt
137 100+
@Pod can you actually reference the ActiveX Calendar in the way you're suggesting? I can understand that working from a form-build calendar, but I was hoping to avoid adding one of them in.
Jul 5 '11 #12
Mihail
759 512MB
Why not use IsDate() function to verify if the value in your text box is a valid date ?
Jul 6 '11 #13
Adam Tippelt
137 100+
I am Mihail - that's exactly what my own code uses. But the problem is that the system has it's own built in error/messagebox for textboxes formatted for dates. I'm trying to stop this firing so that it'll display my own message instead.
Jul 6 '11 #14
Adam Tippelt
137 100+
Mine would be to clear any format of the TextBox control on Entry (the event), and determine it again After Update (event) by the value entered. That way you wouldn't be constrained by the Format while entering data.
Unfortunately your suggestion does not quite work NeoPa. The calendar icon only appears when you enter the textbox (and subsequently disappears when you exit the textbox), so to disable the textbox's format On Entry would be to remove that functionality completely.

I tried applying a similar sort of strategy to things like the Keydown event, and while this works the problem with that strategy is the calendar icon doesn't seem to disappear, so you're left with an unusuable and misleading calendar icon, and I can't seem to get it to disappear...
Jul 6 '11 #15
Mihail
759 512MB
So Adam, do not format the text box. Make a label where you show the good format to enter (i.e yyyy:mm:zz). Then check using code if the user enter data as you teach him in the label. It is just an idea. More: I think that NeoPa's suggestion to use a Calendar control is the best. What about to replace your text box with the Calendar control ?
Good luck !
Jul 6 '11 #16
Adam Tippelt
137 100+
Ah. I've just realised that I think I've been thinking of something else when you've all been saying Calendar control...I always forget about ActiveX controls...
Yes maybe that would be a suitable replacement. I'll see how that works.

Cheers.

Adam.
Jul 6 '11 #17
pod
298 100+
I am attaching a simple version of what I was suggesting. I added the onEnter event as well as Neo suggested.

You may want to play with the events to simulate the action as you see fit...

I hope it helps
Jul 6 '11 #18
Adam Tippelt
137 100+
Ah just spotted your example - that's pretty much what I'd ended up doing. Seems to work well enough.

Thanks.

Adam.
Jul 6 '11 #19

Post your reply

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

Similar topics

13 posts views Thread by Jack MacRank | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.