Solved: Need help in enabling/disabling cmdbtns

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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..
 

Attachments

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
 

manukit

Thread Starter
Joined
Jan 1, 2013
Messages
12
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
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...
 
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
 

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.

:)
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Staff online

Top