Results 1 to 15 of 15
  1. #1
    vazdajic is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2016
    Posts
    95

    Deactivate BTN based on CBO value


    Hi everybody.

    Is it posible to hide/disable/deactivate onclick VBA of btnArb (or the whole btn, whatever is easier) in case cboStatus has value=Inaktiv.

    I just need it deactvated, or hidden, or even a message on-click is better than nothing; e.g."Hey, you are about to add a calculation to an inactive work package"..

    I need something. Thank you guys.


    Thanks.

    Click image for larger version. 

Name:	Forum06.jpg 
Views:	15 
Size:	99.2 KB 
ID:	45714

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Me.btnArb.Enabled = Me.cboStatus <> "Inaktiv"

    or Me.btnArb.Visible

    whichever you prefer. I'd go with enabled.? Buttons appearing and disappearing tend to annoy me

    Put it in the Form Current event and cboStatus AfterUpdate event

    If as I would have done the status is

    1 Active
    2 Inactive

    then use Me.cboStatus.Column(1) <> "Inaktiv"
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Won't work. It is a continuous form?
    OP probably has answer from AWF post that was viewed.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Quote Originally Posted by Micron View Post
    Won't work. It is a continuous form?
    OP probably has answer from AWF post that was viewed.
    Never noticed that
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    vazdajic is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2016
    Posts
    95
    Hi there.. Thanks everyone for replying.. Haha, works almost;

    when I have some records Active, some Inactive, it works, but, when I change Inactive to active, I get error.. btw, it is a continious form..

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    but, when I change Inactive to active, I get error.. btw, it is a continious form..
    Well golly gee, show us the code that doesn't work and tell us what error is shown!

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    OP probably has answer from AWF post that was viewed.
    Explanation - OP has cross posted at AWF in the past, so I looked there for a cross post, saw that OP was viewing a similar thread there where the correct solution (IMO) was given. So I expected that this one would soon be marked solved. Not sure why that solution isn't being implemented since we know that you cannot singly hide buttons on a continuous form, nor can you use conditional formatting to hide buttons..
    Last edited by Micron; 07-11-2021 at 01:34 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    vazdajic is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2016
    Posts
    95
    Haha, sorry, silly me.. The DB with vba applied is in ZIP attached

    WWV_Calculations_11.07.2021-ForForum.zip

    Quote Originally Posted by davegri View Post
    Well golly gee, show us the code that doesn't work and tell us what error is shown!

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Why do we need to download a zip file, unzip it and do the rest, when you can show which line the error is on plus the error message.

    Help us to help you.?

    Post the code as text NOT a picture and explain the rest.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    vazdajic is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2016
    Posts
    95
    Hi there.. I have used:
    Private Sub Combo36_AfterUpdate()
    Me.Combo36.Column (1) <> "Inaktiv"
    End Sub

    And it gives an error: Invalid use of property.

    PS: My combo has different name (Combo36) so I have updated the code acquired here on this thread..

    Also, on current form I have:
    Private Sub Form_Current()
    Me.Command32.Enabled = Me.Combo36 <> "Inaktiv"
    End Sub

    (my combo is Command32)


    Quote Originally Posted by Welshgasman View Post
    Why do we need to download a zip file, unzip it and do the rest, when you can show which line the error is on plus the error message.

    Help us to help you.?

    Post the code as text NOT a picture and explain the rest.

  11. #11
    vazdajic is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2016
    Posts
    95
    Sorry, my BTN is Command32

    Quote Originally Posted by vazdajic View Post
    Hi there.. I have used:
    Private Sub Combo36_AfterUpdate()
    Me.Combo36.Column (1) <> "Inaktiv"
    End Sub

    And it gives an error: Invalid use of property.

    PS: My combo has different name (Combo36) so I have updated the code acquired here on this thread..

    Also, on current form I have:
    Private Sub Form_Current()
    Me.Command32.Enabled = Me.Combo36 <> "Inaktiv"
    End Sub

    (my combo is Command32)

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Ok, I suggest you start giving your objects decent names. 6 months down the line Command32 is not going to mean anything to you?,

    The test has to be EXACTLY THE SAME wherever you use it?
    So if you have an ID plus the description, you would use Me.cboStaus.Column(1) If not, then just Me.cboStatus

    You have not even included the button code which I supplied? so your AfterUpdate code is just nonsense?

    Why would you ask for code and then just make it up as you go along?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  13. #13
    vazdajic is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2016
    Posts
    95
    Yeah, you are right.. I was afraid to change names and touch more then needed haha.. Tend to mess things up... Regarding the code, I thought I have used it as advised (post at 6:04 PM)..

    Take care.



    Quote Originally Posted by Welshgasman View Post
    Ok, I suggest you start giving your objects decent names. 6 months down the line Command32 is not going to mean anything to you?,

    The test has to be EXACTLY THE SAME wherever you use it?
    So if you have an ID plus the description, you would use Me.cboStaus.Column(1) If not, then just Me.cboStatus

    You have not even included the button code which I supplied? so your AfterUpdate code is just nonsense?

    Why would you ask for code and then just make it up as you go along?

  14. #14
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Review posts 3 and 7. It matters not if you get this code right, you will make ALL Command32 buttons disappear. Surely that is not the goal?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    did not fix any control names (should have, struggled as a result). Works as far as I can tell. You will find a lot of alterations, mainly because form too wide for my laptop, except for ID field which you shouldn't be revealing to users. I also picked white for detail section colour.

    Basic rules:
    - you cannot CF an unbound field, so I added one to the table.
    - you cannot CF buttons so "Button" is a textbox with no border.
    - border is not a CF property, so doing anything with it in code will affect all controls.
    - alternate row colours won't work. Cannot make bg = row colour AFAIK. Perhaps with another condition IF you can access detail section properties but I'm not going to try.

    If Inaktiv, textbox bg and font goes white. Since it will take focus, clicking on it sets focus to combo if its value is Inaktiv. Otherwise opens other form as before.
    If that happens on a new record will cause an error so I coded for that.

    Would probably be far easier to have a double click event on the ANK field to open form to that record.
    WWV_CalculationsMicron.zip
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 1
    Last Post: 05-24-2018, 03:02 AM
  2. Replies: 1
    Last Post: 08-25-2016, 05:23 AM
  3. Replies: 3
    Last Post: 07-26-2016, 02:12 PM
  4. deactivate a combo box
    By Michael T in forum Forms
    Replies: 4
    Last Post: 11-21-2011, 10:13 AM
  5. F11 deactivate
    By Cheshire101 in forum Security
    Replies: 4
    Last Post: 03-30-2011, 02:19 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