1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Need help in enabling/disabling cmdbtns

Discussion in 'Business Applications' started by manukit, Jan 6, 2013.

Thread Status:
Not open for further replies.
Advertisement
  1. manukit

    manukit Thread Starter

    Joined:
    Jan 1, 2013
    Messages:
    12
    Hello,

    I have a problem when running the vba code for 2 command buttons. Command buttons are log in & log outt. Here i need to disable the log out button while from the sheet/workbook. After i click on log in button only the log out button should enable. I have tried to write the code, but still i am missing something. As i am a starter for this & this is the first time i m trying vba.

    And i need to put a msgbox after clicking login button it should state "log in successfully completed" & for log out "successfully logged out".

    Please let me know where i have gone wrong on this???

    Please see the attached file & help me on this regard.


    Thanks in advance..
     

    Attached Files:

  2. CDHarm

    CDHarm

    Joined:
    May 26, 2011
    Messages:
    255
    Hi,

    For the "Buttons" Try using the ActiveX command button in stead.
    You can then set the "Properties" for it.
    For the "LogOut" you can set the "Enabled" to false.
    Then within your code for them you can set the "Enabled" to True or False when necessary.

    To set the code for the "LogIn" double click it and this will produce the code module for it.
    You can then write the code that you want it to do.
    Try this and let use know.

    Code for LogIn
    Code:
    Private Sub CommandButton1_Click() '' log In
    ActiveSheet.Unprotect
        Cells(Rows.Count, 2).End(xlUp).Offset(1) = Date
        Cells(Rows.Count, 3).End(xlUp).Offset(1) = Now
        Cells(Rows.Count, 3).End(xlUp).NumberFormat = "hh:mm:ss"
        Cells(Rows.Count, 5).End(xlUp).Offset(1) = Environ("username")
        
        CommandButton1.Enabled = False
        CommandButton1.Enabled = True
        ActiveSheet.Protect
    End Sub
    
    Code for Log Out
    Code:
    Private Sub CommandButton2_Click() '''Log Out
    ActiveSheet.Unprotect
        Cells(Rows.Count, 4).End(xlUp).Offset(1) = Now
        Cells(Rows.Count, 4).End(xlUp).NumberFormat = "hh:mm:ss"
       
       CommandButton1.Enabled = True
        CommandButton1.Enabled = False
       ActiveSheet.Protect
    End Sub
    
     
  3. manukit

    manukit Thread Starter

    Joined:
    Jan 1, 2013
    Messages:
    12
    Hey thanks, it's working fine.

    But, is there any option that to freeze top row & auto scroll down when it gets filled.

    and need to know how to put a msgbox, once after clicked - showing "welcome msg for the user".

    thanks...
     
  4. CDHarm

    CDHarm

    Joined:
    May 26, 2011
    Messages:
    255
    Hi,

    You can use the "Freeze Pane" option to freeze the row.
    As for the scroll and msgbox .
    I put something in the following code.

    Code:
    Private Sub CommandButton1_Click() '' log In
    ActiveSheet.Unprotect
        Cells(Rows.Count, 2).End(xlUp).Offset(1) = Date
        Cells(Rows.Count, 3).End(xlUp).Offset(1) = Now
        Cells(Rows.Count, 3).End(xlUp).NumberFormat = "hh:mm:ss"
        Cells(Rows.Count, 5).End(xlUp).Offset(1) = Environ("username")
        
        CommandButton1.Enabled = False
        CommandButton2.Enabled = True
        MsgBox "Welcome Your Logged In"
        ActiveWindow.Panes(ActiveWindow.Panes.Count).ScrollRow = Cells(Rows.Count, 4).End(xlUp).Row - 5
        ActiveSheet.Protect
    End Sub
    
     
  5. manukit

    manukit Thread Starter

    Joined:
    Jan 1, 2013
    Messages:
    12
    Hey Thanks it's working fine & better.

    Thanks a lot, i really appreciated it.

    I hope there is still a lot to learn from all these.

    :)
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1084002

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice