By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
461,995 Members | 548 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 461,995 IT Pros & Developers. It's quick & easy.

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

P: 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
Share this Question
Share on Google+
3 Replies

ADezii
Expert 5K+
P: 8,733
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

P: 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
Expert 5K+
P: 8,733
  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

Post your reply

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