Results 1 to 5 of 5
  1. #1
    dgrimes is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    11

    Need to disable a command button until a certain field is populated

    I have a badge form with a print button at the bottom. I would like this print button disabled until certain fields above are completed. I have text fields and I have radio button (frame) fields connected to other tables. I cannot figure out where or how to write the code that will let me accomplish this. I do not need all the fields on the page complete so I will probably have to name each one. Any help you can give would be appreciated.



    Please be specific on where to put the code. I am still learning the ins and outs.

    Thank you.

  2. #2
    NTC is offline VIP
    Windows 7 64bit Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    one can use either the visible property or the enable property

    ie. me.CommandButtonName.visible = False

    depending on the user interface experience will determine which event to trigger its property change

    to start the command button in a certain state at the change of the form's record use the form's On Current event

  3. #3
    dgrimes is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    11
    But how would I tie that to a certain field? I would like the button to be grayed out until a certain field is populated. Once data is put into that field the button would be enabled again.

  4. #4
    NTC is offline VIP
    Windows 7 64bit Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    in the certain field's After Update event you would add code: me.CommandButtonName.enabled = true

    of course preceding this one must make that button enabled = false ; you can do that as its core property or in the On Current event of the form itself

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    If you were talking about a single Required Field, it would be simple! But since you have multiple required Fields, you'd have to not only check that the current Control is populated, in its AfterUpdate event, but that all other required ones are populated, before Enabling the Command Button. Also, the users would not have any indication of which Controls were required...if they knew this, they'd have filled them in!

    Probably much better would be checking all of the Required Fields/Controls at one site, the OnClick event for the Command Button, and telling the users why the print button isn't working.

    In Form Design View

    1. Hold down <Shift> and Left-Click all Required Controls
    2. Go to Properties – Other
    3. In the Tag Property enter ReqField


    Now, in the Form's Code Module
    Code:
    Private Sub cmdPrintButtonName_Click()
    
    Dim ctl As Control
    
    For Each ctl In Me.Controls
      
      If ctl.Tag = "ReqField" Then
         If IsNull(ctl) Then
           MsgBox "Following Field is Required: " & vbCrLf & vbCrLf & ctl.Name
           Exit Sub
         End If
      End If
    
    Next ctl
    
    'Code to Print goes here
    
    End Sub

    Hopefully, after getting the Messages telling them why the print button isn't working, they'll learn which ones are required!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 07-14-2015, 02:41 PM
  2. Replies: 5
    Last Post: 03-13-2012, 12:28 PM
  3. Disable command button
    By rajulasb in forum Access
    Replies: 2
    Last Post: 08-04-2011, 05:32 AM
  4. Continuous Form Disable Command Button
    By mbake085 in forum Programming
    Replies: 4
    Last Post: 05-27-2011, 08:55 AM
  5. how to disable command button
    By archie in forum Access
    Replies: 1
    Last Post: 08-27-2009, 11:11 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums