Hi All,
I have a form and need to make sure that 5 of those fields have data before the record is saved.
On the form the fields are in the following Tab order:
DATE NOTIFIED, DATE OF INCIDENT, FNAME, LNAME, AGENCY
I have some code on the BeforeUpdate event of the Form which is shown below:
When i test for a value in those columns by hitting the save button(with no data entered), the first field that it detects needs data is Date of Incident. I want it to validate each field based on it's tab position, so it should say DATE OF NOTIFICATION before DATE OF INCIDENT. Maybe I am missing something in my code, or maybe there is a better way to validate these fields. Any Help is appreciated. Thanks in advance. - Private Sub Form_BeforeUpdate(Cancel As Integer)
-
Dim Msg As String, Style As Integer, Title As String
-
Dim DL As String, ctl As Control
-
-
DL = vbNewLine & vbNewLine
-
-
For Each ctl In Me.Controls
-
-
If ctl.Tag = "?" Then
-
If Trim(ctl.Value & "") = "" Then
-
-
Msg = "'" & ctl.Name & "' is Required!" & DL & _
-
"Please enter a value . . ."
-
Style = vbInformation + vbOKOnly
-
Title = "Required Data Missing! . . ."
-
MsgBox Msg, Style, Title
-
ctl.SetFocus
-
Cancel = True
-
Exit For
-
End If
-
End If
-
Next
-
-
End Sub
Please read Before Posting (VBA or SQL) Code
I recently created a function for one of my databases to make sure that the fields that I needed to populated were in fact populated. It doesn't give the control name in the error message, but if you are following a naming convention, you probably wouldn't want the control name anyway. The control's label's caption could work, but I just make the label red and then tell the user to enter data in the highlighted fields. - Private Function VerifyFields() As Boolean
-
On Error GoTo Error_Handler
-
-
VerifyFields = True
-
-
If Me.txtBorrower & "" = "" Then
-
Me.txtBorrower_Label.ForeColor = vbRed
-
VerifyFields = False
-
Else
-
Me.txtBorrower_Label.ForeColor = 8355711
-
End If
-
-
If IsNull(Me.cboLoanType) Then
-
Me.cboLoanType_Label.ForeColor = vbRed
-
VerifyFields = False
-
Else
-
Me.cboLoanType_Label.ForeColor = 8355711
-
End If
-
-
If Me.cboCounty.Visible = True Then
-
If IsNull(Me.cboCounty) Then
-
Me.cboCounty_Label.ForeColor = vbRed
-
VerifyFields = False
-
Else
-
Me.cboCounty_Label.ForeColor = 8355711
-
End If
-
End If
-
-
-
Exit_Procedure:
-
-
Exit Function
-
-
-
Error_Handler:
-
Call ErrorMessage(Err.Number, Err.Description, "Form_frmRequestProcessor: VerifyFields")
-
Resume Exit_Procedure
-
Resume
-
-
-
End Function
You can ignore the error trapping at the end. I called this from a button's OnClick event like you are planning on doing. - If VerifyFields Then
-
'Save your Record here
-
Else
-
MsgBox "Please fill in the highlighted fields."
-
End If
With this code, the highlighted field would remain highlighted until the save button was clicked again, but you could call the VerifyFields function in each of the required controls' AfterUpdate events and it would keep the highlights accurate.
3 9478
Please read Before Posting (VBA or SQL) Code
I recently created a function for one of my databases to make sure that the fields that I needed to populated were in fact populated. It doesn't give the control name in the error message, but if you are following a naming convention, you probably wouldn't want the control name anyway. The control's label's caption could work, but I just make the label red and then tell the user to enter data in the highlighted fields. - Private Function VerifyFields() As Boolean
-
On Error GoTo Error_Handler
-
-
VerifyFields = True
-
-
If Me.txtBorrower & "" = "" Then
-
Me.txtBorrower_Label.ForeColor = vbRed
-
VerifyFields = False
-
Else
-
Me.txtBorrower_Label.ForeColor = 8355711
-
End If
-
-
If IsNull(Me.cboLoanType) Then
-
Me.cboLoanType_Label.ForeColor = vbRed
-
VerifyFields = False
-
Else
-
Me.cboLoanType_Label.ForeColor = 8355711
-
End If
-
-
If Me.cboCounty.Visible = True Then
-
If IsNull(Me.cboCounty) Then
-
Me.cboCounty_Label.ForeColor = vbRed
-
VerifyFields = False
-
Else
-
Me.cboCounty_Label.ForeColor = 8355711
-
End If
-
End If
-
-
-
Exit_Procedure:
-
-
Exit Function
-
-
-
Error_Handler:
-
Call ErrorMessage(Err.Number, Err.Description, "Form_frmRequestProcessor: VerifyFields")
-
Resume Exit_Procedure
-
Resume
-
-
-
End Function
You can ignore the error trapping at the end. I called this from a button's OnClick event like you are planning on doing. - If VerifyFields Then
-
'Save your Record here
-
Else
-
MsgBox "Please fill in the highlighted fields."
-
End If
With this code, the highlighted field would remain highlighted until the save button was clicked again, but you could call the VerifyFields function in each of the required controls' AfterUpdate events and it would keep the highlights accurate.
zmbd 5,501
Expert Mod 4TB
AB may have a non-vba solution: Validation Rules You can use a validation text to relate the information requirements to the user. The user then will have the option to [Esc] out of the record or enter the data.
As to do this at the table or the form level, that depends; however, I tend to do this at the table level and trap for errors if needed.
thanks Seth and zmbd for the quick replies. I think now i have a better understanding of what path to take.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Oleg |
last post by:
Hello there:
I've been trying to create two different sets of required fields in
one form and to use a
radiobutton as sort of a switcher between these sets.
In my HTML form there are two...
|
by: Cliff R. |
last post by:
Hello, I have a form that has a few required fields and also an "agree
to terms" checkbox that must be required. I have used Javascripts for
both functions individually, but I need a little help...
|
by: bufbec1 |
last post by:
I am pretty good with Access, but do not understand VBA. I have
researched this topic and see only VBA answers, so I hope someone can
help with my specific question.
I have 2 fields for an...
|
by: Tien |
last post by:
Hi,
By default, all controls must have a RequiredField control in order to
use more complex validation control e.g. RangeValidator, so how can I
use validation controls with non-required fields?...
|
by: kaosyeti |
last post by:
i have a form that has required fields and i have a delete button, created by
the wizard, that has this code for onclick:
Private Sub cmddeleterecord_Click()
On Error GoTo...
|
by: Dave |
last post by:
Hi,
I'm using .NET 1.1 and wondering if I can use RequiredFieldValidators with
required fields inside user controls.
The page is a type of tabbed panel layout with the divs show/hidden using...
|
by: swingingming |
last post by:
Hi, I made a form based on one table that has several required fields.
If in the form, I leave some of them blank and close the form using
'X', I get 2 warning messages, 1st is "... field is...
|
by: sdavis1970 |
last post by:
I am working on an Access 2002 database where one of the tables has
five required fields making up the key.
There is a form that is linked to this table which is used for adding
new records.
...
|
by: Cubicle Intern |
last post by:
Hi,
I have a form with multiple fields that confirmed before the form is
submitted (ex. email field needs to be completed before the form can
be submitted). Once the required fields are...
|
by: marcher |
last post by:
please ..
i have this form
<FORM action="add.php" method="post">
<TABLE width="100%" border=0>
<TBODY>
<TR>
<TD align=center><FONT color=#ff0000>* </FONT>title:<BR><INPUT size=40
...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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...
|
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...
| |