You are making it way too difficult.
First the table -I would have three fields: UserID, UserName, Password.
(UserID is an autonumber as primary key). Password field has an input mask
of "Password". This hides the actual password from prying eyes.
Now the form - why have users type in their name each time? Make the User
textbox a combobox instead, and
set the row source (in Properties) to the following: SELECT Login.UserID,
Login.UserName, Login.Password FROM Login ORDER BY Login.UserName;
Then set the combobox format properties:
ColumnCount to 3,
ColumnWidths to 0";1";0" (this stores the values UserID, name and Password,
but only shows the UserName. So combobox1.column(0) is the UserID,
column(1) is the name, and column(2) is the password.
Finally set the input mask of the textbox to "Password" so what the user
types doesn't show on the screen.
Now the user types in the password in text2, and the command button, when
clicked, checks the textbox against combobox.column(2), and if they match
entry is allowed.
So the command button code is only this: (note that I give them more
descriptive names: your text2 is txtPwd, combobox is cboLogin)
Private Sub Command5_Click() ' left off error check for brevity
If Me.txtPwd = Me.cboLogin.Column(2) Then
curUser = Me.cboLogin.Column(0)
DoCmd.Close acForm, "LogonForm"
DoCmd.openform "Your Project Form"
Else
If ct < 4 Then
MsgBox "Password not recognized. Try again!", vbOKOnly, "My Project"
ct = ct + 1
Else
DoCmd.Quit
End If
End If
End Sub
Note also the the "ct" variable is not is this click event! Assign the
variable at the form level, up where it says "Option Compare Database" - the
reason is if it was inside the click event it would never reach 4 since each
click would re-initialise it to zero.
Damon
"kennytwk via AccessMonster.com" <u30020@uwe> wrote in message
news:6aa1ee3a926fa@uwe...
> Hi, can anyone tell me where me where i went wrong?, i'm new to vba, the
> code
> may look terrible to u guys, thanks, i have a table "Login" with 2 field
> "Username, Password". Another 2 text box, Text0_Username and
> Text2_Password.
>
> Private Sub Command5_Click()
> On Error GoTo Err_Command5_Click
>
> Dim ct As Integer
> Dim cmd5 As ADODB.Command
> Dim rst1 As ADODB.Recordset
> Dim str1 As String
> Dim fld1 As ADODB.Field
> Dim stDocName As String
> Dim stLinkCriteria As String
>
> Set cmd5 = New ADODB.Command
> With cmd5
> .ActiveConnection = CurrentProject.Connection
> .CommandText = "SELECT Username, Password FROM LOGIN"
> .CommandType = adCmdText
> End With
>
> Set rst1 = cmd5.Execute
> Do Until rst1.EOF
> str1 = ""
> For Each fld1 In rst1.Fields
> str1 = str1 & fld1.Value & vbTab
> Next fld1
> rst1.MoveNext
> Loop
>
>
>
> If (Text0 = fld1 & Text2 = fld1) Then
> stDocName = "Project"
> DoCmd.OpenForm stDocName, , , stLinkCriteria
> Else
> If ct < 4 Then
> MsgBox "Password not recognized. Please Try again!", vbOKOnly
> ct = ct + 1
> Else
> DoCmd.Quit
> End If
> End If
>
> rst1.Close
> Set fld1 = Nothing
> Set rst1 = Nothing
> Set cmd5 = Nothing
>
> Exit_Command5_Click:
> Exit Sub
>
>
> Err_Command5_Click:
> MsgBox Err.Description
> Resume Exit_Command5_Click
>
> End Sub
>
> --
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/For...oding/200612/1
>