I have created a Login form and coded as below (Before that.. I am very new to VB I have the knowledge only of the basic.) I got the code from this forum itself But it is not working properly
Can anybody help me...
My form contains two textboxes 'TextUserID' and 'TxtPassword' and one Command Button 'CmdLogin'
I have opened the Microsoft DAO 3.6 object library

Here is the code

Private Sub CmdLogin_Click()
   If TxtUserID = "" Then
   MsgBox "User id required.", vbExclamation
   TxtUserID.SetFocus
   Exit Sub
   End If
   If TxtPassword = "" Then
   MsgBox "Password required.", vbExclamation
   TxtPassword.SetFocus
   Exit Sub
   End If
   Dim tempRecordset As Recordset, Password As String


  Set tempRecordset = OpenDatabase("I:\My Documents\Login\Admin.mdb").OpenRecordset(" Select* from User where Ucase(trim(UserID))='" & UCase(Trim(Password)) = "")
  If tempRecordset.RecordCount <> 0 Then
         Password = UCase(Trim(tempRecordset("Password")))

   End If


  tempRecordset.Close
  Set tempRecordset = Nothing

  If Password <> UCase(Trim(TxtPassword)) Then
    MsgBox "Incorrect Password", vbExclamation
    Else
    MsgBox "congatulation"
   End If
   TxtPassword = Empty
End Sub

On working the following msg is shown
Runtime error'3078'
The microsoft Jet Databaseengine cannot find the input table or query 'False'.Make sure it exists and that its name is spelled correctly.
For testing this I tried by putting the DAO on the form and connected to the Table then it works by showing the records in the text boxes. But it will not serve my purpose
PLease help me
My purpose is to check the Userid and password in the Access Database where it is stored and allow entry to the Programme

Recommended Answers

All 5 Replies

The datas are stored in ACCESS database named 'Admin' Table 'User' With fields 'UseID' and 'Password'

shouldn't your sql query be something like SELECT * FROM User WHERE UserID = txtUserID ???

I tried
But the following message comes
Run time error '3061'

Too few parameters.Expected 1 (when one field id omitted)
Too few parameters.Expected 2 (When both fields are there)

try
SELECT Password FROM User Where UserID = txtUserID

The first thing you have to do when a error popup must be dubugging. So properly debug the code execution flow. check what are the values in the declared variable in you form. By using this, You can easily findout the error and cause for the error.

Since you are new to this,try the following link

http://www.vbforums.com/showthread.php?516261-Using-VB6-Debug-Introduction

anyway try to code it as shown below.

    Private Sub txtpwd_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbEnter Then
        If Len(Trim(txtlogin)) > 0 And Len(Trim(txtpwd)) > 0 Then
        If CheckPwd(txtlogin, txtpwd) = "ok" Then
        MsgBox "Password ok"
        Else
        MsgBox "Wrong password or Login not found."
        End If
        Else
        MsgBox "Login and password should not be blank"
        End If
        End If
    End Sub
    Private Function CheckPwd(cLogin As String, cPwd As String)
        'in my case i will use dao. you probably using ado just convert it
        Dim rs As Recordset, ret As String
        Set rs = opendatabase("c:\temp\login.mdb").openrecordset("select * from tbllogin where ucase(trim(logname)) = '" & UCase(Trim(cLogin)) & "'")
        If rs.RecordCount <> 0 Then
        If UCase(Trim(rs("pword"))) = UCase(Trim(cPwd)) Then
        ret = "ok"
        Else
        ret = "wrong"
        End If
        Else
        ret = "wrong"
        End If
        rs.Close: CheckPwd = ret
    End Function

Because I hope the problem is in your logic. So try the above code logic.

Hope it helps you...

Have a happy coding...:-D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.