Re: complete all the fields before exit
- From: "Larry Linson" <bouncer@xxxxxxxxxxxxx>
- Date: Wed, 25 Apr 2007 05:15:44 -0500
For a Form with TextBox Controls named txtTextID, txtItemName, txtType,
txtColor, txtWeight, txtHeight, txtWidth, txtDesc, txtSource, txtCategory,
each bound to a data Field in the Table/Query that is the RecordSource of
the Form, the following code in the BeforeUpdate event does what you want.
It cancels the update if in any of the TextBox controls are Null (nothing
ever entered) or a zero-length string (something entered and deleted).
(Note: this is not "finished" code -- it does not include error handling.
You have to determine what error handling you need and add it.)
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.txtTextID = "" Or IsNull(Me.txtTextID) = True Or _
Me.txtItemName = "" Or IsNull(Me.txtItemName) = True Or _
Me.txtType = "" Or IsNull(Me.txtType) = True Or _
Me.txtColor = "" Or IsNull(Me.txtColor) = True Or _
Me.txtWeight = "" Or IsNull(Me.txtWeight) = True Or _
Me.txtHeight = "" Or IsNull(Me.txtHeight) = True Or _
Me.txtWidth = "" Or IsNull(Me.txtWidth) = True Or _
Me.txtDesc = "" Or IsNull(Me.txtDesc) = True Or _
Me.txtSource = "" Or IsNull(Me.txtSource) = True Or _
Me.txtCategory = "" Or IsNull(Me.txtCategory) = True Then
MsgBox "All information must be filled in"
Cancel = True
End If
Exit_Proc: Exit Sub
End Sub
Larry Linson
Microsoft Access MVP
"Carol Shu" <CarolShu@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:DF6BFCD1-6BF4-4443-BE10-566C3DF04B16@xxxxxxxxxxxxxxxx
Hi, Larry, could you help me start the code....please...
"Larry Linson" wrote:
"Carol Shu" <CarolShu@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:425BA773-AFF9-4C8D-A18C-BE817833B430@xxxxxxxxxxxxxxxx
that's say I have a form, there are 10 fields in this form, how do I
make
user complete all the fields before exit the database, if user only
enter
9
fields, the screen will popup a message like "can not exit unless all
the
fields are compete.." please help, many thanks.
Put code in the BeforeUpdate event of the Form to validate that none of
the
fields are empty or null, if any are, set the Cancel argument to True
(cancels the update event), issue a MsgBox explaining why you are not
allowing the update, and exit.
Larry Linson
Microsoft Access MVP
.
- Follow-Ups:
- Re: complete all the fields before exit
- From: Carol Shu
- Re: complete all the fields before exit
- References:
- Re: complete all the fields before exit
- From: Larry Linson
- Re: complete all the fields before exit
- Prev by Date: Form to update table and detect changes
- Next by Date: Re: Using DMax with a restricted set of records
- Previous by thread: Re: complete all the fields before exit
- Next by thread: Re: complete all the fields before exit
- Index(es):
Relevant Pages
|