I am started a new with VB6 Access project. I am connected database with ADODB, DSN Method that Code Given below.

'======================In module ==============
'=================== Connection With Database ===============
'======================================================
Public CNN As New ADODB.Connection
Public RS As New ADODB.Recordset
Public cString As String

Public Sub Main()
Set CNN = New ADODB.Connection
cString = "DSN=Customer"
With CNN
.ConnectionString = cString
.CommandTimeout = 20
.CursorLocation = adUseClient
.Open
End With
RS.Open "select * from TB_Users", CNN, adconstatic, adLockOptimistic
MsgBox "Connection Established" '& " -" & CNN.Provider, vbOKOnly + vbInformation, "Connection"
'Debug.Print "connection Established"
frmLogin.Show
End Sub

This is writted in Module. This is working properly. But My problem is I can't get username and Password from from Table to my login form. I have written some code that is given below.

'======================================================
'================In FRMLogin=======================
'======================================================
Dim RS As New ADODB.Recordset

Private Sub cmdCancel_Click()
End
End Sub

Private Sub cmdOK_Click()
RS.Open ("Select * from TB_Users 'Where Name = " & TXTUserName & " and Password=" & TXTPassword & ""), CNN
If RS.EOF = False Then
FRMMDIMain.Show
Unload Me
Else
MsgBox "Invalid Password, try again!", , "Login"
TXTUserName.SetFocus
End If
End Sub

When I run this getting Debug Messege

Runtime Error - '-2147217904(800440e10)'

[Microsoft][ODBC Microsoft Access Driver] Too few Parameters. Expected 2.

I can't understand this messege ..... Please Help Me... Plese

Also please give the source code to insert data to Table and update data.... Please

With Regards

Manojthahal

Recommended Answers

All 4 Replies

Hi,

I can't check your code right now but below is a similar code I used once for a login form (no need for the module):

Option Explicit
Dim rs As Recordset
Dim db As Connection

Private Sub cmdCancel_Click()

    Me.Hide
    Unload Me
    
End Sub
Private Sub cmdOK_Click()

    Set db = New Connection
    db.Open "PROVIDER=MSDataShape;Data PROVIDER=MSDASQL;dsn=Manual;uid="";pwd="";"
    Set rs = New Recordset
    rs.Open "select * from users", db, adOpenStatic, adLockOptimistic
    rs.Find "[username] = '" & Me.TXTUserName & "' "
    
    If Not rs.EOF Then
    
        If rs![Password] = Me.TXTPassword Then
        
                frmmain.Show
                Unload Me
                
        Else
        
                MsgBox "Invalid Password, try again!", , "Login"
                Me.TXTPassword = ""
                Me.TXTUserName = ""
                TXTPassword.SetFocus
                SendKeys "{Home}+{End}"
                
        End If
    
    Else
    
        MsgBox "Invalid Username, try again!", , "Login"
        Me.TXTPassword = ""
        TXTUserName.SetFocus
        SendKeys "{Home}+{End}"
    
    End If

End Sub

I hope this will work with you.

use the followingto open the connection while using DSN

Conn.Open "DSN=mySystemDSN;" & "Uid=myUsername;" & "Pwd=myPassword"

Hi,

in ur login form, SQL Statement, there is a Single quote before "Where" key word, check it. One more thing, never Declare and object in Module as Public and again Declare it in another Form , check RS.
check this statement"

RS.Open ("Select * from TB_Users Where Name = '" & TXTUserName & "' and Password='"  & TXTPassword & "'"), CNN

Before this code is executed, check whether connection to db is made or not...

Regards
Veena

Thanks Veena, Thaks

Now I am working a New project.

Hi,

in ur login form, SQL Statement, there is a Single quote before "Where" key word, check it. One more thing, never Declare and object in Module as Public and again Declare it in another Form , check RS.
check this statement"

RS.Open ("Select * from TB_Users Where Name = '" & TXTUserName & "' and Password='"  & TXTPassword & "'"), CNN

Before this code is executed, check whether connection to db is made or not...

Regards
Veena

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.