|
-
May 26th, 2000, 09:30 AM
#1
I just completed a nice little module, that uses a login box..
heres the code for it..
add all of it into a bas module
Code:
Option Explicit 'All variables have to be declared
Dim MessageUser As String 'wrong username message
Dim MessagePass As String 'wrong password message
Dim MessageUserPass As String 'combined wrong user/pass
Dim UserPassMsg As String 'holds the msgbox choice for user/pass
Dim UserMsg As String 'holds msgbox choise for user
Dim PassMsg As String 'holds msgbox choice for pass
Public CountThis As Integer 'counter
Public Sub UserPass(User As String, Pass As String, UserTxt As String, PassTxt As String, FormToLoad As Form, ThisForm As Form) 'declare the sub
'User - this is the username
'Pass - this is the password
'Usertxt - this is the textbox for the username
'Passtxt - this is the textbox for the password
'FormToLoad - this is the form you are gonaa load(protected)
'ThisForm - this is the current form, set this as Me
MessageUser = "Wrong UserName" 'set the MessageUser variable to a string
MessagePass = "Wrong PassWord" 'set the MessagePass variable to a string
MessageUserPass = MessageUser & " And " & MessagePass 'set the MessageUser and MessagePass variables to two strings
CountThis = CountThis + 1 'set CountThis to itself plus one
If CountThis > 3 Then 'if CountThis has a value greater than 3 then do this
MsgBox "You tried to login more than three times, I dont think you know the password!", vbCritical, "Bye Bye" 'messagebox containing the byebye message
End 'byebye
End If 'end the if statement
If UserTxt <> User And PassTxt <> Pass Then 'if usertxt doesnot equal user, and passtxt doesnot equal pass, then do this
UserPassMsg = MsgBox(MessageUserPass, vbCritical + vbRetryCancel, MessageUserPass) 'message saying its wrong
If UserPassMsg = vbCancel Then 'if the return value of the message equals the cancel button, then do this
End 'byebye
ElseIf UserPassMsg = vbRetry Then 'else, if the return value equals the retry button, then do this
End If 'end the if statement
ElseIf UserTxt <> User Then 'else, if usertxt is equal to user then do this
UserMsg = MsgBox(MessageUser, vbCritical + vbRetryCancel, MessageUser) 'messagebox
If UserMsg = vbCancel Then 'if the return value is the cancel button, then do this
End 'byebye
ElseIf UserMsg = vbRetry Then 'else, if the return value equals the retry button, then do this
End If 'end the if statement
ElseIf PassTxt <> Pass Then 'else, if passtxt is equal to pass, then do this
PassMsg = MsgBox(MessageUser, vbCritical + vbRetryCancel, MessagePass) 'messagebox
If PassMsg = vbCancel Then 'if the return value is equal to the cancel button then do this
End 'byebye
ElseIf UserMsg = vbRetry Then 'else, if the return value is equal to the retry button, then do this
End If 'end the if statement
ElseIf UserTxt = User And PassTxt = Pass Then 'else, if usertxt is equal to user, and passtxt is equal to pass, then do this
MsgBox "Acess Granted", vbExclamation, "Granted Acess" 'message
Unload ThisForm 'unload the current form (me)
Load FormToLoad 'load the specified form
FormToLoad.Show ' show the specified form
End If 'end the if statement
End Sub ' end the sub
call it like this
Code:
Private Sub Command1_Click()
UserPass("Hello", "Hello", txtUser, txtPass, frmMain, Me)
End Sub
it is simple to use, simple to modify, and includes lots of comments, I have tested it, no bugs.
if you find any bugs, or anything, please tell me.
I know it can only support one username, I am working on that.
please give me some ideas on how to do this, but NO F***ing CODE, I want to do it myself<James/John: is it ok to blank cuss words out like that?>
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|