Hi,
I have a form in Access.
Before a user clicks Add Record, I would like a check to be performed to ensure the fields do not equal blank.
The forms contains fields which are bound.
Many thanks
1 1946
There are a couple of different ways to do this. You can use validation rules on each control to make sure that it isn't Null (see Allen Browne Validation Rules). Or you can use VBA and create a set of If statements in the form's BeforeUpdate event to test teach control to make sure it isn't blank. I actually created a procedure that does this for me with just a few lines of code for each form and lets me pick which controls are required. To use this method, create a new Class Module and name it clsRequired and then paste the following code into it:
Then create another Class Module and name it clsMessage and paste the following code into it: - '---------------------------------------------------------------------------------------
-
' Module : clsMessage
-
' Author : sschrock
-
' Date : 11/7/2013
-
' Purpose : This class module will be passed a series of text strings and then will
-
' return the collection as a single string will proper comma placements
-
' as well as any additional words needed to make it grammatically correct.
-
'
-
'---------------------------------------------------------------------------------------
-
-
-
Private intUpper As Integer
-
Private intLower As Integer
-
Private arrText() As String
-
-
-
-
Private Sub Class_Initialize()
-
-
intUpper = 0
-
ReDim arrText(0) As String
-
-
End Sub
-
-
Public Sub AddText(Text As String)
-
-
intUpper = intUpper + 1
-
ReDim Preserve arrText(intUpper) As String
-
arrText(intUpper) = Text
-
-
End Sub
-
-
Public Function Message(Optional addPeriod As Boolean = False) As String
-
Dim i As Integer
-
Dim strMsg As String
-
-
Select Case intUpper
-
Case 1
-
strMsg = arrText(1)
-
-
Case 2
-
strMsg = arrText(1) & " and " & arrText(2)
-
-
Case Else
-
For i = 1 To intUpper
-
Select Case i
-
Case 1
-
strMsg = arrText(i)
-
-
Case Is <= (intUpper - 1)
-
strMsg = strMsg & ", " & arrText(i)
-
-
Case Is = intUpper
-
strMsg = strMsg & " and " & arrText(i)
-
-
End Select
-
Next
-
-
End Select
-
-
If addPeriod Then
-
strMsg = strMsg & "."
-
End If
-
-
Message = strMsg
-
-
End Function
-
-
Public Property Get ItemCount() As Integer
-
ItemCount = intUpper
-
End Property
-
Then, for each control that you want to be required in the form, put the text Req in the Tag property (found at the bottom of the Other tab in the property window). To utilize all this code, you would put the following in your Add Record button's OnClick event: - Dim clsReq As clsRequired
-
Set clsReq = New clsRequired
-
-
clsReq.CheckControls Me.Name, clsReq.txt + clsReq.cbo 'this checks just textboxes and comboboxes
-
-
If Not clsReq.Completed Then
-
MsgBox clsReq.Message
-
Else
-
'perform your code here
-
End If
-
-
Set clsReq = Nothing
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Unregistered |
last post by:
Hi,
First, excuse me for my bad English, I'm Dutch.... :-)
I know there's a lot of information about disabeling form fields, but
cannot find the script I need:
I'm looking for a script...
|
by: Rick Knight |
last post by:
I need to have a couple of form fields filled in according to the value of
a third field before the entire form is submitted. I have searced and I
can't find any information on how to do this. Is...
|
by: bobby1041 |
last post by:
Hi All!
I am trying to make several fields in a HTML form validated, but only
when a dynamic checkbox is selected. I am not sure how to do this.
Here is a snippet of the dynamic checkbox...
|
by: C |
last post by:
Hi,
I have a web form which is quite long.
My first field is required.
If my user submits the form the page just sits there and
the do not see my validation message at the top of my page.
...
|
by: Zameer Syed |
last post by:
I have a webform in which users enter their information
and there is a button at the end of form,which when
clicked should open a word document with fields filled in
dynamically with the...
|
by: griemer |
last post by:
I have a database like this
id, field1,field2,field3,field4,field5
Database contains 100 rows, some rows have no fields filled, some
1field , some 2 fields etc.
How would i count the...
|
by: fstenoughsnoopy |
last post by:
I have a customer order database and I need to pull a customers
information, ie first name, last name, address, city, state, zip,
phone, etc, into the oder table. i don't know how to go about...
|
by: mtuller |
last post by:
I am creating a page for nomination and want to let the information
pass if any field are filled out, but if none are filled out, a
message will appear. I can't get the check to happen on multiple...
|
by: apking |
last post by:
hi Friends,
how to filled values from mysql database using php in html form.actually when user wants to edit his account.when fields filled with old details from musql database
for example :...
|
by: Samuel Murray |
last post by:
G'day everyone
I'm not a JavaScript programmer, so I wonder if you could point me in
the right direction or simply tell me how to do the following.
I'd like to submit a patch for the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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...
| |