A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Close Form Crashes Database



 
 
Thread Tools Display Modes
  #1  
Old September 24th, 2005, 12:21 PM
Debbie D.
external usenet poster
 
Posts: n/a
Default Close Form Crashes Database

Hi all,

I have a form that is based on a table where all the fields are set to
required. On the same form I have a Close button. If I do not input data
into a feilds Access informs me correctly that the feild is set to required.
However, if by 'user' mistake half way through the filling process the user
exits via the close button I receive the message, "The fieild cannot contain
Null value because the Required field is set to True. Enter a value for this
field". Problem is I cannot do so, tried the ESC key but it seem to be in a
loop. I there any way to correct this or have the database close correctly
without saving the record.

Thanks for taking the time to read this, any and all help welcome.

Debbie D.
  #2  
Old September 24th, 2005, 04:59 PM
JB
external usenet poster
 
Posts: n/a
Default

One option would be to define default values for all the fields either in the
table def or using vb code when the user creates a new record. Another
option is reconsider the use of "is required" for the fields. Do you really
need it? Instead, you could do some checking when the user tries to close
the form. If you are not using VB, then setting defaults would be the
simpliest given that in the real world, the user can always find a way of
closing without completing the form.--
JB


"Debbie D." wrote:

Hi all,

I have a form that is based on a table where all the fields are set to
required. On the same form I have a Close button. If I do not input data
into a feilds Access informs me correctly that the feild is set to required.
However, if by 'user' mistake half way through the filling process the user
exits via the close button I receive the message, "The fieild cannot contain
Null value because the Required field is set to True. Enter a value for this
field". Problem is I cannot do so, tried the ESC key but it seem to be in a
loop. I there any way to correct this or have the database close correctly
without saving the record.

Thanks for taking the time to read this, any and all help welcome.

Debbie D.

  #3  
Old September 24th, 2005, 05:33 PM
'69 Camaro
external usenet poster
 
Posts: n/a
Default

Hi, Debbie.

I there any way to correct this or have the database close correctly
without saving the record.


I suggest creating a default value for every required field in the table.
If this is not feasible, then open the form in Design View and select the
"Format" tab. Scroll down to the Control Box Property and set it to No. In
the Close button's OnClick procedure add code that checks the fields for NULL
values and when it finds at least one field empty, asks the user whether to
close the form or go back to the record for further editing. For example:

Private Sub CloseBtn_Click()

On Error GoTo ErrHandler

Dim ans As Integer

If ((Nz(Me!txtA.Value, "") = "") Or (Nz(Me!txtB.Value, "") = "")) Then
ans = MsgBox("You must have a value for every field" & vbCrLf & _
"or you cannot save this record." & vbCrLf & vbCrLf & _
"Select OK to exit without saving or" & vbCrLf & _
"select Cancel to return to the record.", _
vbCritical + vbOKCancel, "Cannot Save!")

If (ans = vbOK) Then
Me.Undo
DoCmd.Close acForm, Me.Name
End If
Else
DoCmd.Close acForm, Me.Name
End If

Exit Sub

ErrHandler:

MsgBox "Error in CloseBtn_Click( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub

.... where CloseBtn is the name of the button, and txtA and txtB are the
names of the text boxes on the form. Change these names to those of the
form's text boxes and add the other controls that require values in the IF
statement by adding additional "OR" operators between each control's check
for NULL. Save and compile the code, then open the form in Form View.

The user will need to use the Close button to close the form instead of
using the "X" in the Title Bar to close the form. There will still be an
error if the user closes the database when the form is incomplete, but it
won't be a surprise to the user that the record is not saved and that the
database closes.

The fact that the database crashes is a separate issue. This may be caused
by an unstable operating system, an older version of Access, a faulty
installation of Access, invalid VBA code, a corrupt database, et cetera.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.


"Debbie D." wrote:

Hi all,

I have a form that is based on a table where all the fields are set to
required. On the same form I have a Close button. If I do not input data
into a feilds Access informs me correctly that the feild is set to required.
However, if by 'user' mistake half way through the filling process the user
exits via the close button I receive the message, "The fieild cannot contain
Null value because the Required field is set to True. Enter a value for this
field". Problem is I cannot do so, tried the ESC key but it seem to be in a
loop. I there any way to correct this or have the database close correctly
without saving the record.

Thanks for taking the time to read this, any and all help welcome.

Debbie D.

  #4  
Old September 24th, 2005, 07:25 PM
Debbie D.
external usenet poster
 
Posts: n/a
Default

JB,

Many thanks for your help. I reset some of the 'required' defaults. Debbie
D.

"JB" wrote:

One option would be to define default values for all the fields either in the
table def or using vb code when the user creates a new record. Another
option is reconsider the use of "is required" for the fields. Do you really
need it? Instead, you could do some checking when the user tries to close
the form. If you are not using VB, then setting defaults would be the
simpliest given that in the real world, the user can always find a way of
closing without completing the form.--
JB


"Debbie D." wrote:

Hi all,

I have a form that is based on a table where all the fields are set to
required. On the same form I have a Close button. If I do not input data
into a feilds Access informs me correctly that the feild is set to required.
However, if by 'user' mistake half way through the filling process the user
exits via the close button I receive the message, "The fieild cannot contain
Null value because the Required field is set to True. Enter a value for this
field". Problem is I cannot do so, tried the ESC key but it seem to be in a
loop. I there any way to correct this or have the database close correctly
without saving the record.

Thanks for taking the time to read this, any and all help welcome.

Debbie D.

  #5  
Old September 24th, 2005, 07:26 PM
Debbie D.
external usenet poster
 
Posts: n/a
Default

Gunny,

Thanking you very much. The code worked great. Simply perfection. That
for all the help from everyone.

Debbie D. (UK)

"'69 Camaro" wrote:

Hi, Debbie.

I there any way to correct this or have the database close correctly
without saving the record.


I suggest creating a default value for every required field in the table.
If this is not feasible, then open the form in Design View and select the
"Format" tab. Scroll down to the Control Box Property and set it to No. In
the Close button's OnClick procedure add code that checks the fields for NULL
values and when it finds at least one field empty, asks the user whether to
close the form or go back to the record for further editing. For example:

Private Sub CloseBtn_Click()

On Error GoTo ErrHandler

Dim ans As Integer

If ((Nz(Me!txtA.Value, "") = "") Or (Nz(Me!txtB.Value, "") = "")) Then
ans = MsgBox("You must have a value for every field" & vbCrLf & _
"or you cannot save this record." & vbCrLf & vbCrLf & _
"Select OK to exit without saving or" & vbCrLf & _
"select Cancel to return to the record.", _
vbCritical + vbOKCancel, "Cannot Save!")

If (ans = vbOK) Then
Me.Undo
DoCmd.Close acForm, Me.Name
End If
Else
DoCmd.Close acForm, Me.Name
End If

Exit Sub

ErrHandler:

MsgBox "Error in CloseBtn_Click( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub

... where CloseBtn is the name of the button, and txtA and txtB are the
names of the text boxes on the form. Change these names to those of the
form's text boxes and add the other controls that require values in the IF
statement by adding additional "OR" operators between each control's check
for NULL. Save and compile the code, then open the form in Form View.

The user will need to use the Close button to close the form instead of
using the "X" in the Title Bar to close the form. There will still be an
error if the user closes the database when the form is incomplete, but it
won't be a surprise to the user that the record is not saved and that the
database closes.

The fact that the database crashes is a separate issue. This may be caused
by an unstable operating system, an older version of Access, a faulty
installation of Access, invalid VBA code, a corrupt database, et cetera.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.


"Debbie D." wrote:

Hi all,

I have a form that is based on a table where all the fields are set to
required. On the same form I have a Close button. If I do not input data
into a feilds Access informs me correctly that the feild is set to required.
However, if by 'user' mistake half way through the filling process the user
exits via the close button I receive the message, "The fieild cannot contain
Null value because the Required field is set to True. Enter a value for this
field". Problem is I cannot do so, tried the ESC key but it seem to be in a
loop. I there any way to correct this or have the database close correctly
without saving the record.

Thanks for taking the time to read this, any and all help welcome.

Debbie D.

  #6  
Old September 24th, 2005, 09:47 PM
'69 Camaro
external usenet poster
 
Posts: n/a
Default

Hi, Debbie.

You're very welcome. Glad it helped.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.


"Debbie D." wrote in message
...
Gunny,

Thanking you very much. The code worked great. Simply perfection. That
for all the help from everyone.

Debbie D. (UK)

"'69 Camaro" wrote:

Hi, Debbie.

I there any way to correct this or have the database close correctly
without saving the record.


I suggest creating a default value for every required field in the table.
If this is not feasible, then open the form in Design View and select the
"Format" tab. Scroll down to the Control Box Property and set it to No.
In
the Close button's OnClick procedure add code that checks the fields for
NULL
values and when it finds at least one field empty, asks the user whether
to
close the form or go back to the record for further editing. For
example:

Private Sub CloseBtn_Click()

On Error GoTo ErrHandler

Dim ans As Integer

If ((Nz(Me!txtA.Value, "") = "") Or (Nz(Me!txtB.Value, "") = ""))
Then
ans = MsgBox("You must have a value for every field" & vbCrLf & _
"or you cannot save this record." & vbCrLf & vbCrLf & _
"Select OK to exit without saving or" & vbCrLf & _
"select Cancel to return to the record.", _
vbCritical + vbOKCancel, "Cannot Save!")

If (ans = vbOK) Then
Me.Undo
DoCmd.Close acForm, Me.Name
End If
Else
DoCmd.Close acForm, Me.Name
End If

Exit Sub

ErrHandler:

MsgBox "Error in CloseBtn_Click( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub

... where CloseBtn is the name of the button, and txtA and txtB are the
names of the text boxes on the form. Change these names to those of the
form's text boxes and add the other controls that require values in the
IF
statement by adding additional "OR" operators between each control's
check
for NULL. Save and compile the code, then open the form in Form View.

The user will need to use the Close button to close the form instead of
using the "X" in the Title Bar to close the form. There will still be an
error if the user closes the database when the form is incomplete, but it
won't be a surprise to the user that the record is not saved and that the
database closes.

The fact that the database crashes is a separate issue. This may be
caused
by an unstable operating system, an older version of Access, a faulty
installation of Access, invalid VBA code, a corrupt database, et cetera.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message
will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the
question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember
that
questions answered the quickest are often from those who have a history
of
rewarding the contributors who have taken the time to answer questions
correctly.


"Debbie D." wrote:

Hi all,

I have a form that is based on a table where all the fields are set to
required. On the same form I have a Close button. If I do not input
data
into a feilds Access informs me correctly that the feild is set to
required.
However, if by 'user' mistake half way through the filling process the
user
exits via the close button I receive the message, "The fieild cannot
contain
Null value because the Required field is set to True. Enter a value
for this
field". Problem is I cannot do so, tried the ESC key but it seem to be
in a
loop. I there any way to correct this or have the database close
correctly
without saving the record.

Thanks for taking the time to read this, any and all help welcome.

Debbie D.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tell if Form is a Dialog Alex Using Forms 7 August 30th, 2005 06:22 PM
Database - Insert not working LaRue05 General Discussion 3 August 29th, 2005 11:44 PM
What is MDE Charlie General Discussion 4 August 24th, 2004 04:15 PM
Strange stLinkCriteria behaviour on command button Anthony Dowd Using Forms 3 August 21st, 2004 03:01 AM
dlookup miaplacidus Using Forms 9 August 5th, 2004 09:16 PM


All times are GMT +1. The time now is 08:18 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.