Results 1 to 8 of 8
  1. #1
    mick3911 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2013
    Location
    Wirral, UK
    Posts
    66

    Set Command Button Not to Work Unless Certain Fields Contain Data

    I have a form where there is a Command Button to e-mail a report.


    What I would like to happen is that the Command Button will not function unless the Investigation and Root Cause fields on the form have had data entered into them.

    Command Button is named: View/Send Report
    First field that I want to have data in is named: Investigation Findings
    Second field that I want to have data in is named: Root Cause

    Is this possible, if it is how do I go about doing it?

    I’m guessing that it can be done by VBA but my VBA knowledge is not that great.

    Many thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    put events in all the AFTERUPDATE events to enable the button

    Code:
    sub txtInvestFind_Afterupdate
      EnableBtn
    end sub
    
    
    sub txtRoot_Afterupdate EnableBtn end sub
    sub EnableBtn() btnEmail.enabled = Not IsNull(txtInvestFind) and Not IsNull(txtRoot)
    end sub

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,425
    cross posted here with responses https://www.access-programmers.co.uk...=1#post1608172

    @mick - please read this link about the etiquette of cross posting http://www.excelguru.ca/content.php?184

  4. #4
    mick3911 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2013
    Location
    Wirral, UK
    Posts
    66
    Many thanks

  5. #5
    mick3911 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2013
    Location
    Wirral, UK
    Posts
    66
    Quote Originally Posted by Ajax View Post
    @mick - please read this link about the etiquette of cross posting http://www.excelguru.ca/content.php?184
    Noted, apologies.

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Why not leaving the button enabled and adding the check and a message in the OnClick event of the button?
    Code:
    If IsNull(txtInvestFind) Or IsNull(txtRoot) then
       msgbox "Please fill in ,,,,,,"
       exit sub
    end if
    Cheers,
    Vlad

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    IsNull is fine as long as there's no chance of the field containing an empty string. Would also consider a different approach if the count of fields to be evaluated gets larger. I usually would employ a routine that loops certain controls right from the beginning. It's easily expanded and beats re-writing code when you suddenly decide you need to add 2 more.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    mick3911 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2013
    Location
    Wirral, UK
    Posts
    66
    Many thanks for the help. Now sorted.

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

Similar Threads

  1. Replies: 5
    Last Post: 05-10-2014, 12:25 PM
  2. Replies: 3
    Last Post: 05-16-2012, 10:20 AM
  3. Command Button Wizard and Matching Fields
    By tylerg11 in forum Forms
    Replies: 5
    Last Post: 10-07-2011, 01:07 PM
  4. Command button doesn't work when DB is opened
    By buckeye4 in forum Access
    Replies: 3
    Last Post: 02-23-2011, 01:32 PM
  5. Replies: 1
    Last Post: 07-27-2010, 02:27 PM

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