CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Login Form

  1. #1
    Join Date
    Nov 2005
    Posts
    56

    Login Form

    Hi people, its me the noob again haha .. something's gone wrong with my login form. compile error .. rstUsers.Index = "UserID" .. the index seems to have some kind of problem. anyone can help?



    Private Sub btnCancel_Click()

    End

    End Sub

    Private Sub Form_Load()

    btnLogin.Enabled = False
    gintKeypresscount = 0

    End Sub

    Private Sub txtLoginID_GotFocus()

    gintKeypresscount = 0

    End Sub

    Private Sub txtLoginID_KeyPress(KeyAscii As Integer)

    If KeyAscii = 13 Then

    KeyAscii = 0

    gintKeypresscount = 1
    SearchEmployee

    End If

    End Sub

    Private Sub txtLoginID_LostFocus()

    If gintKeypresscount = 0 And txtLoginID.Text <> "" Then
    gintKeypresscount = 1
    SearchEmployee
    End If

    End Sub

    Private Sub txtPassword_GotFocus()

    If txtLoginID.Text = "" Then
    txtLoginID.SetFocus
    End If

    gintKeypresscount = 0

    End Sub

    Private Sub txtPassword_KeyPress(KeyAscii As Integer)

    If KeyAscii = 13 Then
    If gintKeypresscount = 0 And txtPassword.Text <> "" Then
    KeyAscii = 0
    gintKeypresscount = 1
    SearchPassword
    End If
    End If

    If txtPassword <> "" Then
    btnLogin.Enabled = True
    End If

    End Sub

    Sub SearchEmployee()

    'establish connection to database
    Dim dcnRefund As New ADODB.Connection
    dcnRefund.CursorLocation = adUseClient
    dcnRefund.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source = D:\Alvin Tan\My Documents\Refund\Refund.mdb;"

    'create recordset
    Dim rstUsers As ADODB.Recordset
    Set rstUsers = New ADODB.Recordset
    rstUsers.CursorType = adOpenKeyset
    rstUsers.LockType = adLockOptimistic
    rstUsers.Open "tblRefundUsers", dcnRefund, adOpenStatic, adLockOptimistic

    rstUsers.Index = "UserID"
    rstUsers.Seek "=", txtLoginID.Text

    If rstUsers.NoMatch Then
    MsgBox "Sorry, User not found!", vbExclamation
    gintKeypresscount = 0
    txtLoginID.Text = ""
    txtLoginID.SetFocus
    Else
    txtPassword.SetFocus
    btnLogin.Enabled = True
    End If

    rstUsers.Close

    dcnRefund.Close

    End Sub

    Sub SearchPassword()

    'establish connection to database
    Dim dcnRefund As New ADODB.Connection
    dcnRefund.CursorLocation = adUseClient
    dcnRefund.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source = D:\Alvin Tan\My Documents\Refund\Refund.mdb;"

    'create recordset
    Dim rstUsers2 As ADODB.Recordset
    Set rstUsers2 = New ADODB.Recordset
    rstUsers2.CursorType = adOpenKeyset
    rstUsers2.LockType = adLockOptimistic
    rstUsers2.Open "tblRefundUsers", dcnRefund, adOpenStatic, adLockOptimistic

    If txtLoginID.Text = "" Then
    MsgBox "Please enter User Login ID", vbExclamation
    gintKeypresscount = 0
    txtLoginID.Text = ""
    txtLoginID.SetFocus
    Exit Sub
    End If

    rstUsers2.Index = "UserID"
    rstUsers2.Seek "=", txtLoginID.Text

    If txtPassword.Text = "" And gintKeypresscount = 1 Then
    MsgBox "Please enter password", vbExclamation
    gintKeypresscount = 0
    txtPassword.SetFocus
    Else
    If rstUsers2("UserPwd") = txtPassword.Text Then
    gintLoginID = UCase(txtLoginID.Text)
    Unload Me
    frmMainMenu.Show
    Else
    MsgBox "Wrong Password!", vbExclamation
    gintKeypresscount = 0
    txtPassword.SetFocus
    txtPassword.Text = ""
    End If
    End If

    rstUsers2.Close
    dcnRefund.Close

    End Sub

  2. #2
    Join Date
    Aug 2000
    Location
    Essex, Uk
    Posts
    1,214

    Re: Login Form

    Why are you :

    rstUsers.CursorType = adOpenKeyset
    rstUsers.LockType = adLockOptimistic
    rstUsers.Open "tblRefundUsers", dcnRefund, adOpenStatic, adLockOptimistic

    setting the cursortype and locktype then overriding them on the open command.

    remove the adopenstatic and adlockoptimistic on the open command line.

    Also you should put some handling in to ensure index etc are supported by the recordset.

    i.e.
    If rstUsers.Supports(adIndex) And rstUsers.Supports(adSeek) Then
    ........
    If you find my answers helpful, dont forget to rate me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured