![]() |
UserForm Password
I have just inherited a spreadsheet with userform and the vba lines
below (Yes, I happen to a beginner in VBA). The problem I am having with the userform is that once it pops up, you click on the create template command button and the program starts. Now the problem is it doesn't ask you to enter a password even though it has textbox and a command button to ok this. Please help me explain how I can incorporate a password in the vb lines below so that everytime a correct password is entered the program is activated. Many thanks. Private Sub cmdCreate_Click() frmauthorisation.Hide Call CreateTemplate Me.lbldone.Caption = "A total of " & iWCount & " workbooks" _ & " containing a total of " & iCCount & " worksheets created." Me.lbldone.Visible = True frmauthorisation.Show End Sub Private Sub cmdCancel_Click() Unload frmauthorisation End Sub Private Sub cmdOK_Click() If vPW = sPW Then Me.cmdcreate.Enabled = True Else Me.cmdcreate.Enabled = False MsgBox "Incorrect Authorisation Code!", vbCritical, "Authorisation" End If End Sub Private Sub Label1_Click() End Sub Private Sub lblDone_Click() End Sub Private Sub txtPW_Change() vPW = Me.txtpw.Text Me.cmdOk.Enabled = Len(vPW & vbNullString) 0 End Sub Private Sub UserForm_Initialize() sPW = Chr$(112) & Chr$(104) & Chr$(79) & Chr$(110) & Chr$(108) & Chr$(121) End Sub |
UserForm Password
You have a line in the Private Sub cmdOK_Click() routine.
If vPW = sPW Then It looks like those variables are set somewhere else. But maybe you could use the same technique: Private Sub cmdCreate_Click() frmauthorisation.Hide If vPW = sPW Then Call CreateTemplate Me.lbldone.Caption = "A total of " & iWCount & " workbooks" _ & " containing a total of " & iCCount & " worksheets created." Me.lbldone.Visible = True else msgbox "wrong password" end if frmauthorisation.Show End Sub But this is just a guess. Ola2B wrote: I have just inherited a spreadsheet with userform and the vba lines below (Yes, I happen to a beginner in VBA). The problem I am having with the userform is that once it pops up, you click on the create template command button and the program starts. Now the problem is it doesn't ask you to enter a password even though it has textbox and a command button to ok this. Please help me explain how I can incorporate a password in the vb lines below so that everytime a correct password is entered the program is activated. Many thanks. Private Sub cmdCreate_Click() frmauthorisation.Hide Call CreateTemplate Me.lbldone.Caption = "A total of " & iWCount & " workbooks" _ & " containing a total of " & iCCount & " worksheets created." Me.lbldone.Visible = True frmauthorisation.Show End Sub Private Sub cmdCancel_Click() Unload frmauthorisation End Sub Private Sub cmdOK_Click() If vPW = sPW Then Me.cmdcreate.Enabled = True Else Me.cmdcreate.Enabled = False MsgBox "Incorrect Authorisation Code!", vbCritical, "Authorisation" End If End Sub Private Sub Label1_Click() End Sub Private Sub lblDone_Click() End Sub Private Sub txtPW_Change() vPW = Me.txtpw.Text Me.cmdOk.Enabled = Len(vPW & vbNullString) 0 End Sub Private Sub UserForm_Initialize() sPW = Chr$(112) & Chr$(104) & Chr$(79) & Chr$(110) & Chr$(108) & Chr$(121) End Sub -- Dave Peterson |
All times are GMT +1. The time now is 03:03 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com