473,414 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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 15284
NeoPa
32,556 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,556 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,556 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

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

Similar topics

24
by: jrefactors | last post by:
I have an upload file operation in the web application. UploadForm.jsp is the form, and UploadAction.jsp is the form processing. The web server is Websphere. //UploadForm.jsp <FORM...
5
by: lottaviano | last post by:
I am using Access 2002 and have two tables (Main and Actions) linked (in Relationships) on one field "CAL_ID" (primary key in Main Table). Main Table is a list of equipment. Actions Table lists...
5
by: Horst Walter | last post by:
What is wrong here? IPAddress ipAddress = IPAddress.Parse("10.10.20.1"); IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, this.port); this.tcpClient = new TcpClient(ipEndPoint); // PROBLEM HERE...
13
by: Jack MacRank | last post by:
Hello, I'm coding a webform application in C# (ASP.NET 1.1 SP1 with VS.NET 2003 Pro on WinXP SP2 using IIS 5.1). I created a seperate "data" class to house all the MySQL connection and sql...
8
by: Pieter | last post by:
Hi, I'm having some weird problem using the BackGroundWorker in an Outlook (2003) Add-In, with VB.NET 2005: I'm using the BackGroundWorker to get the info of some mailitems, and after each item...
2
by: Mr Flibble | last post by:
Hi All I've decided to put my stylesheets in a base64 .resource file for deployment and versioning reasons. I dont know if it's a great idea to do this but I couldn't think of another way of...
3
by: keithb | last post by:
Using a GridView, I get a "Specified cast is not valid" error when binding the Visible propery of a hyperlink control to a DataTable text field. The error goes away if I replace the data binding...
0
by: keikoo | last post by:
Hi, I need some help with this control. There's a windows form with a axwebbrowser control inside, so users can navigate to a page and it's necessary to keep the session, because, users will...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
2
by: Emily Lisker | last post by:
I am using Yes/No/Null number combo boxes per Allen Browne's instructions (http://allenbrowne.com/NoYesNo.html). My validation rule is: "Is Null Or 0 Or -1" I copied Allen Browne's lookup box...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
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,...
0
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...
0
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...
0
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...
0
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...

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.