Results 1 to 10 of 10
  1. #1
    Tall_Paul is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Feb 2018
    Posts
    3

    Question Can I disable a button if a field is empty (null)?

    I have a field on my table called PPTfile. This field simply stores the location and file name of a PowerPoint file. On a form I have a button that will open the PowerPoint file when clicked. Is it possible to disable this button if there is nothing in the PPTfile field for the selected record?

  2. #2
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    I don't know whether it possible to read the PPt text from Access as I've never tried
    However you could add a Boolean field called PPt to the table and mark it true for the relevant records.
    Include the field (hidden) on you form and use something like

    Code:
    me.buttonname.visible=me.ppt
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    if you are saying you are storing the path and filename as a field in a table and want to disable the button if the field is blank then you can use (for single forms only)

    me.buttonname.visible=not isnull(nameoffield)

    or if the field can contain a zero length string or space

    me.buttonname.visible=trim(nz(nameoffield,""))<>""

    put the code in the form current event and the nameoffield afterupdate event

    if your form is continuous, then you need to use conditional formatting - which does not work with buttons, instead create a textbox and format it to look like a button

  4. #4
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Hi Ajax
    Reading it again, I think your interpretation of the question is more likely what the OP meant
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    Tall_Paul is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Feb 2018
    Posts
    3

    Smile It is a continuous form

    That is exactly correct: I have a field in a table that holds the path and filename of a ppt file that launches when clicked. So you are saying that since it is a continuous form that I am using I need to format a textbox to look like a button and use conditional formatting to make it look like a button because on a continuous form all of the unbound buttons will reflect the state of only the selected record correct?

    I imagine any VBA code that I have for the OnClick of the button will be easily transferable to the OnClick of the textbox as well.

    I will research conditional formatting and see how to do it. Thank you.

    - Paul

    Quote Originally Posted by Ajax View Post
    if you are saying you are storing the path and filename as a field in a table and want to disable the button if the field is blank then you can use (for single forms only)

    me.buttonname.visible=not isnull(nameoffield)

    or if the field can contain a zero length string or space

    me.buttonname.visible=trim(nz(nameoffield,""))<>""

    put the code in the form current event and the nameoffield afterupdate event

    if your form is continuous, then you need to use conditional formatting - which does not work with buttons, instead create a textbox and format it to look like a button

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    use conditional formatting to make it look like a button because on a continuous form all of the unbound buttons will reflect the state of only the selected record correct?
    correct

    I imagine any VBA code that I have for the OnClick of the button will be easily transferable to the OnClick of the textbox as well.
    correct - just be aware that visibility is not an option with conditional formatting, use the enabled/disabled property so it is greyed out

    I need to format a textbox to look like a button
    there is more than one way to crack an egg. Instead of the button or textbox, you can use the double click event of the control that holds the path name - then in your code have a qualifier

    Code:
    if not isnull(mypathcontrol) then
        'open file
    end if
    and if you want, in that controls controltip property put something like 'Double click to open file'

    and/or you can use conditional formatting on that control to show say green text or background if the field is populated

  7. #7
    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
    Quote Originally Posted by Ajax View Post

    ...Instead of the button or textbox, you can use the double click event of the control...
    That's the approach I've always used for this task, with Continuous/Datasheet Forms, and it's always been readily accepted by users, even non-tech savvy users.

    Linq ;0)>

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I have used the form DblClick event with a label with instruction: "Double click in left margin of a record to view lab data.". This means the RecordSelectors property has to be set to Yes.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    Code:
    If IsNull(PPTfile Field) Then
    btnforPPTfile.Enabled = False
    Else
    btnforPPTfile.Enabled = True
    End If

    Just ensure the field is null and not zero length string when no data is present.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    And yes, all instances of the button will reflect the same status. But is that an issue?

    Ajax's code is simpler - no If Then.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 7
    Last Post: 01-19-2018, 04:41 PM
  2. Replies: 1
    Last Post: 05-18-2016, 01:25 PM
  3. Replies: 4
    Last Post: 02-24-2016, 09:29 AM
  4. disable dsum field with button
    By tagteam in forum Access
    Replies: 6
    Last Post: 11-19-2013, 02:25 PM
  5. Button Hidden When Field Is Null
    By rad1182 in forum Programming
    Replies: 5
    Last Post: 08-14-2012, 02:33 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