473,400 Members | 2,145 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,400 software developers and data experts.

how to disable command button when any field of form is empty?

23
Hi, i am making A database. In this db there are many form with command buttons. Each command button executes many queries. These command buttons will not work properly if any field of the form remains empty. so how can i disable or inactive the command button when any field of form is empty?
Nov 10 '13 #1
3 4425
ADezii
8,834 Expert 8TB
There are several ways to accomplish this, and this approach is simply one of them:
  1. For any Form Field that must contain a Value, set the Tag Property of that Form Field to 'Req' (Required).
  2. Execute the following Code which will:
    1. Loop thru every Control in the Form.
    2. If the Control has a Tag Property = Yes, and if the Value in this Control is Empty (NULL), set the Value of a Boolean Variable (blnFldEmpty) to True and exit the For...Next Loop.
  3. The last Code Line will check the Value of this Variable (True/False) then set the Enabled State of the Command Button appropriately (Enabled/Disabled).
    Expand|Select|Wrap|Line Numbers
    1. Dim ctl As Control
    2. Dim blnFldEmpty As Boolean
    3.  
    4. blnFldEmpty = False     'Initialize
    5.  
    6. For Each ctl In Me.Controls
    7.  If ctl.Tag = "Req" And IsNull(ctl) Then
    8.    blnFldEmpty = True
    9.      Exit For
    10.  End If
    11. Next
    12.  
    13. Me![cmdTest].Enabled = Not blnFldEmpty
Nov 10 '13 #2
moonrb
23
THANK U SO MUCH FOR YOUR REPLY BUT i NEED Whenever i click command button in a form that executes many queries at a time, it(command button) should check all the fields of the form filled up or not? if filled up then the command button should work otherwise not and beside the empty field should appear a message like this -"this filled cannot be empty". My command button name is "POST". PLZ GIVE ME ANOTHER SOLUTION WITH VB CODE.
Nov 11 '13 #3
ADezii
8,834 Expert 8TB
  1. This is not what you indicated in your first Post.
    how to disable command button when any field is empty
  2. Everything that you need is indicated in my Reply with a slight adjustment:
    Expand|Select|Wrap|Line Numbers
    1. If Not blnFldEmpty Then
    2.   'Execute Code
    3. End if
Nov 11 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mr. Bungle | last post by:
When importing excel from access I am fully aware that one can import directly into a table. Can you get as specific via code or something to import data from an excel sheet to a FORM (Not Table)...
1
by: microsoft | last post by:
I am looking for code for a button on a website, and I want it to prevent users from clicking more than once while their request is being processed. I would like it to disable or hide the button...
1
by: olivier.wambacq | last post by:
hello, This sounds simple but I can't seem to manage... So I'm in a form, and have got a button to "open" (make visible) a subform. the subform actually contains fields from the same table as...
4
by: teric2 | last post by:
Hello Everyone! I am trying to use the following code in an on click event procedure from a command button on a custom form set as a dialog box. The dialog box is opened from another form. The...
1
by: elLiven | last post by:
Hi I'm trying to learn VBA in Excel mysel. Getting stuck on userforms. I can create a userform with optionbuttons and command buttons. I want to know how to have the form display the...
6
by: Proaccesspro | last post by:
I have a command button on a form. When the command button is clicked, I would like to relocate it on the form. I thought I would do so using the LEFT and TOP properties, but I'm getting no love. ...
1
by: ALaurie10 | last post by:
I keep getting the "in use by another user or process" error. Is there some way to lock the table temporary. I want a user to click a command button on a form that runs a Macro that opens a...
14
by: alnino | last post by:
Hi, I have a command button on a form that the user can use to browse to a file and the user can select that file and a hyperlink to that file is stored in a txtfield for that record. I then...
3
by: extrym | last post by:
I have 2 forms, "Staff" and "Security" (without the ""'s). The Staff form has the following fields: staff_ID staff_name staff_number staff_DOB priority The Security form contains the...
10
by: tajuddin | last post by:
I wanted to have a Command Button on a form to save a record & then ask to open a new record. I am new to access. I have MDFID on a form with primary key. Thanks Seth, To be frank, I...
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
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
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...
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,...
0
jinu1996
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...
0
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...
0
isladogs
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 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.