473,385 Members | 1,927 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,385 software developers and data experts.

Closing Forms and Eliminating Default Warnings

Something odd I just noticed on one of my forms that has a "Close MS
Access button. It seems I can't use the close button if I have wrong
data entered in any of the form's combo boxes. (I only have 2 combo
boxes and one close button on the form).

The combo boxes only allow date formats to be entered. If I enter a
non-date format I get an obvious default warning saying "The value
you entered isn't valid for this field"

My code to close the form is quite simple:

Private Sub cmdCloseForm_Click()
DoCmd.Close acForm, "frmStudentInfo", acSaveNo
End Sub
I have two questions on this issue:

1) How does one change the text on the default warning (as I can't
find a code number associated with this warning, like one can find
for errors)?

2) How can I suppress the warning when I click the close button?
Marcus
******

Nov 13 '05 #1
3 1416
You need to do some data validation. Unfortunatly, Access does not have
the Validate event like VB6 does. You can not put code in the LostFocus
event because you could end up in an endless loop. Probably the best
option here is simply add code so your procedure looks like this:

Private Sub cmdCloseForm_Click()
'************************************************* *************
'New code, check values of combo boxes if there is anything in
there
If Len(Trim$(Combo1)) > 0 then 'this means there is a value present
If Not IsDate(Combo1) then 'THIS MEANS THE VALUE IS NOT A
DATE VALUE
Msgbox "Please supply a valid date.",
vbExclamation, "Invalid Date"
Compbo1.SetFocus 'put the cursor back in the
Combo1 box
Exit Sub
End If
End If
If Len(Trim$(Combo2)) > 0 then 'this means there is a value present
If Not IsDate(Combo2) then 'THIS MEANS THE VALUE IS NOT A
DATE VALUE
Msgbox "Please supply a valid date.",
vbExclamation, "Invalid Date"
Compbo2.SetFocus 'put the cursor back in the
Combo2 box
Exit Sub
End If
End If
'Resume original code

'************************************************* ****************************************
DoCmd.Close acForm, "frmStudentInfo", acSaveNo
End Sub
David Hodgkins, MCSD, MCDBA, MCSE
dh*******@jstarsoftware.com
www.jstarsoftware.com

Nov 13 '05 #2
Access will try to process the events for the control before it processes
the Close button. That means you have to deal with the "bad data" error
first.

This is an engine-level error, so you can use the Error event of the form to
trap it. The event has an argument named DataErr, and it will have the value
2113 for this error. You can trap and handle it however you please, but if
you just discard the error (by setting Response to acDataErrContinue) it
does not solve the unsuitable data, and perhaps worse this will happen in
all cases where the engine raises DataErr 2113.

The simplest solution would be to teach the user to press the Esc key twice
to undo the record, and then try closing again.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Marcus" <to*******@yahoo.ca> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
Something odd I just noticed on one of my forms that has a "Close MS
Access button. It seems I can't use the close button if I have wrong
data entered in any of the form's combo boxes. (I only have 2 combo
boxes and one close button on the form).

The combo boxes only allow date formats to be entered. If I enter a
non-date format I get an obvious default warning saying "The value
you entered isn't valid for this field"

My code to close the form is quite simple:

Private Sub cmdCloseForm_Click()
DoCmd.Close acForm, "frmStudentInfo", acSaveNo
End Sub
I have two questions on this issue:

1) How does one change the text on the default warning (as I can't
find a code number associated with this warning, like one can find
for errors)?

2) How can I suppress the warning when I click the close button?
Marcus
******

Nov 13 '05 #3
Many thanks for the solutions. I will try them

Marcus
********

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Nick Coghlan | last post by:
Time for another random syntax idea. . . So, I was tinkering in the interactive interpreter, and came up with the following one-size-fits-most default argument hack: Py> x = 1 Py> def...
22
by: John Fisher | last post by:
void f(int p) { } Many (most?) compilers will report that p is unreferenced here. This may not be a problem as f may have to match some common prototype. Typically pointers to functions are...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
1
by: Cedric | last post by:
Hello, I have a form that could be closed by a code keyed or selected in a combobox but when I select my code my program end up with an error (NullReferenceException) and not when I keying the...
1
by: e_man_online | last post by:
Hi, I have a VStudio 2003 project that had code like: Private Sub frmAnyForm_Closing(<parameters list...>) Handles MyBase.Closing and this project was converted to .NET 2.0 Everything...
0
by: robert | last post by:
I have noticed in .net 2 that when authenticating a user, setting the cookie using either redirectfromloginpage or setauthcookie, specifying true for the persistent parameter that the cookie is...
4
by: Academic | last post by:
Does it make sense to put this If e.Cancel Then Exit Sub at the beginning of form closing events so if the user cancels the app's exiting in one Closing routine he will not be asked again by...
2
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
I am (still) relatively new to Windows applications, most of my experience has been Web based, and I am confused about what exactly happens when the Main() method is called and how to manipulate...
4
Fr33dan
by: Fr33dan | last post by:
Hi, I'm having trouble with a multi-threaded program crashing on a specific machine when the worker thread is not initialized at when the _FormClosing method of my main form called. Here is my...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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,...

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.