Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default Userform won't show when file re-opened

I have a password validation file that will execute code to open another file
when successful. User ID and Password are input in a userform when file
opens. My problem is after successful execution, if I re-open the file in
the same Excel session, the userform does not show. Not certain why this is.

Following code runs when workbook is opened:

Option Explicit

Private Sub workbook_open()

Application.EnableCancelKey = xlDisabled
Application.ScreenUpdating = False
Windows("ABS Open1.xls").Visible = True
Application.Run ("HideAll")
Windows("ABS Open1.xls").Visible = False
Application.ScreenUpdating = True
Application.Run ("Start")

End Sub

VBA Macro "Start" is modular. Code is:

Option Explicit

Private Sub Start()

Password_Validation.Show

End Sub

This code executes when command button is pressed on userform:

Private Sub cmbEnter_Click()

Dim UserName
Dim Password
UserName = txbUserName.Value
Password = txbPassword.Value

Application.EnableEvents = False
Application.ScreenUpdating = False
Windows("ABS Open1.xls").Visible = True
Application.Run ("UnhideAll")

On Error GoTo errorhandler

With Password

If Password =
Application.WorksheetFunction.VLookup(txbUserName. Value, _
Range("'Users'!PassTable"), 2, False) Then

If UserName = "admin" Then
Unload Me
Application.EnableEvents = True
Exit Sub
End If

With Worksheets("Cost Center")
Range("'Cost Center'!D1").Value = UserName
Range("'Cost Center'!B3").AutoFilter Field:=1, Criteria1:="x"
End With

Windows("ABS Open1.xls").Visible = False
Unload Me
Select_Cost_Center.Show
Exit Sub

End If

End With

errorhandler:
MsgBox ("User Name or Password Invalid. Please try again.")
txbUserName.Value = ""
txbPassword.Value = ""
Me.txbUserName.SetFocus
Windows("ABS Open1.xls").Visible = False

End Sub

Not sure why userform will not show when file is closed then re-opened in
same Excel session? If I restart Excel, everything works fine.
--
Thanks,

Gerry O.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Userform won't show when file re-opened

As a guess you are having an issue with Events... You turn them off in
cmbEnter_Click() without turning them back on again (they might get turned on
but only if UserName = "admin")... Events are a persistent setting so you
need to be very careful with it...
--
HTH...

Jim Thomlinson


"Gerry O" wrote:

I have a password validation file that will execute code to open another file
when successful. User ID and Password are input in a userform when file
opens. My problem is after successful execution, if I re-open the file in
the same Excel session, the userform does not show. Not certain why this is.

Following code runs when workbook is opened:

Option Explicit

Private Sub workbook_open()

Application.EnableCancelKey = xlDisabled
Application.ScreenUpdating = False
Windows("ABS Open1.xls").Visible = True
Application.Run ("HideAll")
Windows("ABS Open1.xls").Visible = False
Application.ScreenUpdating = True
Application.Run ("Start")

End Sub

VBA Macro "Start" is modular. Code is:

Option Explicit

Private Sub Start()

Password_Validation.Show

End Sub

This code executes when command button is pressed on userform:

Private Sub cmbEnter_Click()

Dim UserName
Dim Password
UserName = txbUserName.Value
Password = txbPassword.Value

Application.EnableEvents = False
Application.ScreenUpdating = False
Windows("ABS Open1.xls").Visible = True
Application.Run ("UnhideAll")

On Error GoTo errorhandler

With Password

If Password =
Application.WorksheetFunction.VLookup(txbUserName. Value, _
Range("'Users'!PassTable"), 2, False) Then

If UserName = "admin" Then
Unload Me
Application.EnableEvents = True
Exit Sub
End If

With Worksheets("Cost Center")
Range("'Cost Center'!D1").Value = UserName
Range("'Cost Center'!B3").AutoFilter Field:=1, Criteria1:="x"
End With

Windows("ABS Open1.xls").Visible = False
Unload Me
Select_Cost_Center.Show
Exit Sub

End If

End With

errorhandler:
MsgBox ("User Name or Password Invalid. Please try again.")
txbUserName.Value = ""
txbPassword.Value = ""
Me.txbUserName.SetFocus
Windows("ABS Open1.xls").Visible = False

End Sub

Not sure why userform will not show when file is closed then re-opened in
same Excel session? If I restart Excel, everything works fine.
--
Thanks,

Gerry O.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default Userform won't show when file re-opened

Thanks for the quick response. This did indeed appear to be the problem. I
added to code to re-enable events and it now works just fine.

--
Thanks,

Gerry O.


"Jim Thomlinson" wrote:

As a guess you are having an issue with Events... You turn them off in
cmbEnter_Click() without turning them back on again (they might get turned on
but only if UserName = "admin")... Events are a persistent setting so you
need to be very careful with it...
--
HTH...

Jim Thomlinson


"Gerry O" wrote:

I have a password validation file that will execute code to open another file
when successful. User ID and Password are input in a userform when file
opens. My problem is after successful execution, if I re-open the file in
the same Excel session, the userform does not show. Not certain why this is.

Following code runs when workbook is opened:

Option Explicit

Private Sub workbook_open()

Application.EnableCancelKey = xlDisabled
Application.ScreenUpdating = False
Windows("ABS Open1.xls").Visible = True
Application.Run ("HideAll")
Windows("ABS Open1.xls").Visible = False
Application.ScreenUpdating = True
Application.Run ("Start")

End Sub

VBA Macro "Start" is modular. Code is:

Option Explicit

Private Sub Start()

Password_Validation.Show

End Sub

This code executes when command button is pressed on userform:

Private Sub cmbEnter_Click()

Dim UserName
Dim Password
UserName = txbUserName.Value
Password = txbPassword.Value

Application.EnableEvents = False
Application.ScreenUpdating = False
Windows("ABS Open1.xls").Visible = True
Application.Run ("UnhideAll")

On Error GoTo errorhandler

With Password

If Password =
Application.WorksheetFunction.VLookup(txbUserName. Value, _
Range("'Users'!PassTable"), 2, False) Then

If UserName = "admin" Then
Unload Me
Application.EnableEvents = True
Exit Sub
End If

With Worksheets("Cost Center")
Range("'Cost Center'!D1").Value = UserName
Range("'Cost Center'!B3").AutoFilter Field:=1, Criteria1:="x"
End With

Windows("ABS Open1.xls").Visible = False
Unload Me
Select_Cost_Center.Show
Exit Sub

End If

End With

errorhandler:
MsgBox ("User Name or Password Invalid. Please try again.")
txbUserName.Value = ""
txbPassword.Value = ""
Me.txbUserName.SetFocus
Windows("ABS Open1.xls").Visible = False

End Sub

Not sure why userform will not show when file is closed then re-opened in
same Excel session? If I restart Excel, everything works fine.
--
Thanks,

Gerry O.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Currency Format on UserForm when opened! Robo[_2_] Excel Discussion (Misc queries) 3 May 8th 07 02:42 PM
Properties window show nothing for a userform Cheer-Phil-ly Excel Discussion (Misc queries) 0 July 27th 06 07:15 PM
cannot open the excel file, the file is already opened cannot open the excel document Excel Discussion (Misc queries) 1 May 19th 06 07:45 AM
Copying the Editing in one file to Another opened XLS file Ahmad Excel Worksheet Functions 1 May 27th 05 02:04 PM
Can macro/userform run depending on HOW workbook is opened? grasping@straws Excel Discussion (Misc queries) 1 December 28th 04 03:19 PM


All times are GMT +1. The time now is 12:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"