Protecting a cmdButton

sanand
07-30-2002, 12:33 PM
Hi there,

I am trying to hide or unhide a cmd button based on the
user password entry.

Here's what I want:

If the password is "super" then make the cmdEdit
button visible, if the pw is "view" hide this button,
and if none of these two, then display an error
message. Here is code I'm using:

****** Code starts here ********

Private Sub OK_Click()
On Error Resume Next

Select Case txtPassword.Text

Case "super"
frmMain.Show
frmMain.cmdEdit.Visible = True
Me.Hide

Case "view"
frmMain.Show
frmMain.cmdEdit.Visible = False
Me.Hide

Case Else
MsgBox "Invalid User Name and Password, try again!", , "Login - Try Again"
txtPassword.SetFocus
SendKeys "{Home}+{End}"

End Select

End Sub

****** end of the code ********

When I enter the "view" (without quotes) as pw,
it does not hide the cmdEdit button.

Any help with this code is appreciated.
TIA

Iceplug
07-30-2002, 12:43 PM
What is your cmdEdit.Visible before you start the program?
Do you set the cmdEdit.Visible in your Form_Load event?

godonlyknows200
07-30-2002, 12:44 PM
Try this:


Function CheckSuper()
If txtPassword.Text="super" Then
cmdEdit.Visible=True
Else
Exit Sub
End If
End Function

Function CheckView()
If txtPassword.Text="view" Then
cmdEdit.Visible=False
Else
Exit Sub
End Sub

Private Sub OK_Click()
Call CheckSuper
Call CheckView
End Sub


Just a way of doing it that I just typed up, hope it helps. If not sorry, I wrote it up right here without testing it.

sl8rz
07-30-2002, 12:46 PM
The first thing I'd do is run the program in debug mode and follow it right through your select statement with a pw of "view" -- you'll know if it is even entering the "view" case at all. You'll then know exactly what needs debugging.

sanand
07-30-2002, 01:21 PM
Thanks godonlyknows200

After making a little change in your code, I tried the function, and it did not work.

Here's what I've.
I have a login form, which after PW verification, opens a tabbed
form frmMain. The frmMain has a cmdEdit button on the form (not on any tab).
Now if the pw = super, it should open the frmMain with cmdEdit visible.
If the pw=view, then the cmdEdit should be invisible.

Here is the modified version of your code:
Public Sub CheckView()
If txtPassword.Text = "view" Then
frmMain.Show
frmMain.cmdEdit.Visible = False
Me.Hide
Else
Exit Sub
End If
End Sub


Public Sub CheckSuper()
If txtPassword.Text = "super" Then
frmMain.Show
frmMain.cmdEdit.Visible = True
Me.Hide
Else
Exit Sub
End If

End Sub

Private Sub cmdOK_Click()
CheckSuper
CheckView

End Sub

The problem is if I enter the pw as "view", it does not hid
the cmdEdit button.

Any idea?
TIA

sanand
07-30-2002, 01:23 PM
Thanks Iceplug for your response.

The cmdEdit button is visible in design view.
I'm trying to make it visible/invisible thru code.

Your assistance is appreciated.
TIA

Iceplug
07-30-2002, 01:40 PM
Maybe you should attach your code so we can check it. :)

NateBrei
07-30-2002, 03:34 PM
I'd create a public variable and set it in your login form based on the password. Then in your main form's Form_Load event, you can do a Select Case statement on the value of the variable to determine whether the button should be displayed or not.

Nate

sanand
08-05-2002, 05:08 PM
Thanks every one who responded to my request.

I am sorry it took me so long. I was out of the office
for a few days.

I checked my code posted earlier with case statement.
That was fine and is working as expected. The problem
was with some other function calls.

It's working now.

TIA

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum