PDA

View Full Version : Logging in problem again.



MNJ
01-15-2007, 08:23 PM
I'm so so sorry to bother you guys after each question again. But after I completed everything, this runtime error ' 1004' reappeared!

Could you guys kindly help me look thru. Previously, I had a post on this : http://www.vbaexpress.com/forum/showthread.php?t=10635 too.


Private Sub CommandButton1_Click()
Dim w As Worksheet, c As Range, R As Range
Dim strUser As String, strPword As String, strWs As String
Sheets("main").Select ' this line is highlited.

'Note use of UCASE()
strUser = UCase(Me.TextBox1.Value)
strPword = Me.TextBox2.Text

Select Case strUser
'Note letters
Case "USER"
'Note letters
If strPword = "USER" Then
'Only show sheets in this list
Sheets("INVENTORY").Visible = False
Sheets("INVENTORY").Visible = False
Sheets("INVENTORY2").Visible = False
Sheets("INVENTORY3").Visible = False

Sheets("Inventory4").Visible = False
Sheets("RM").Visible = xlSheetVisible
Sheets("ELE").Visible = xlSheetVisible
'Hide columns for 'USER'
Sheets("ELE").Range("L1:BA1").Columns.Hidden = True
Sheets("RM").Range("F1:BA1").Columns.Hidden = True
'Hide columns for 'USER'
Sheets("ELE").Range("L1:BA1").Columns.Hidden = True

'Disable Format/Columns/Unhide menu item for 'USER'
With Application.CommandBars("Format").Controls("Column").Controls("Unhide")
.Enabled = False
.Visible = False
End With
Unload Me
Else
MsgBox "Incorrect password"
End
End If
'Note capital letters
Case "ADMIN"
'Note capital letters
If strPword = "ADMIN" Then
'View all sheets
For Each Sh In Sheets
Sh.Visible = xlSheetVisible
Next Sh

'Show columns for 'ADMIN'
Sheets("ELE").Range("L1:BA1").Columns.Hidden = False

Unload Me
Else
MsgBox "The password is incorrect"
Workbooks("SI.XLS").Close SaveChanges:=False
End
End If
Case Else
MsgBox "Incorrect password or user name", vbCritical + vbOKOnly, "Error!"
Workbooks("SI.XLS").Close SaveChanges:=False
End Select
End Sub



Could anyone please tell me why ? : pray2:

:bow: Thanks thanks!!

johnske
01-15-2007, 10:33 PM
That's usually highlighted because that sheet doesn't exist. The way it's spelt in the code must be exactly the way it's spelt on your sheet-tab - no leading or trailing spaces etc....

MNJ
01-15-2007, 11:03 PM
Thanks for telling me. I outlooked that Factor. =)