i recieving error on rs.open up to conn on private sub cmdlogin

Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql As String
Dim cmd As ADODB.Command
Dim button As String

Private Sub ConnectToDB()
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & App.Path _
& "\dbHMS.mdb"
conn.Open
End Sub
Private Sub OpenNewRecordSet()
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenStatic, adCmdText
End Sub

Private Sub cmdcancel_Click()
Unload Me
End Sub

Private Sub cmdlogin_Click()
'here is my error'
rs.Open "select AccountID, UserName, Password from Account where UserName = '" _
& txtuser.Text & "' And Password = '" & txtpass.Text, conn

If Not rs.RecordCount = 0 Then
frmMain.Show
Unload Me
Else
MsgBox "Invalide Input", vbExclamation + vbOKOnly, "Error"
End If

End Sub

Put the following code BEFORE your Rs.Open statement -

Set Rs = New ADODB.Recordset

This should solve your problem.

ahhmmm...still no but i did add what you said add set rs = new adodb.recordset before my rs.open here is the code, i change it a bit..
the error say's(Command Text was not set for the command object

Private Sub cmdcancel_Click()
Unload Me
End Sub

Private Sub cmdlogin_Click()

Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim sql As String
Dim button As String

Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & App.Path & _
"\dbHMS.mdb"
conn.Open

Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenStatic, adCmdText   '<<<error here'

rs.Open "select AccountID, UserName, Password from Account where UserName = '" _
& txtuser.Text & "' And Password = '" & txtpass.Text & "'", conn

If Not rs.RecordCount = 0 Then
frmMain.Show
Unload Me
Else
MsgBox "Invalide Input", vbExclamation + vbOKOnly, "Error"
End If

End Sub

never mind i already got it i mixed it with some repeating codes even i dont know how it works but it did works wtf >.<

yeah thanks that will help and an additional reference

#
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenStatic, adCmdText '<<<error here'

can you tell me where is sql? and what will rs open?

Try this code

Private Sub cmdcancel_Click()
Unload Me
End Sub
Private Sub cmdlogin_Click()
 
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim sql As String
Dim button As String
 
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & App.Path & _
"\dbHMS.mdb"
conn.Open
 
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "select AccountID, UserName, Password from Account where UserName = '" _
& txtuser.Text & "' And Password = '" & txtpass.Text & "'", conn
 
If Not rs.RecordCount = 0 Then
frmMain.Show
Unload Me
Else
MsgBox "Invalide Input", vbExclamation + vbOKOnly, "Error"
End If
 
End Sub

mine are different but it works

here is my code

Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim sql As String

Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdlogin_Click()

Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & App.Path & _
"\dbHMS.mdb"
conn.CursorLocation = adUseClient
conn.Open

Set rs = New ADODB.Recordset

rs.Open "select AccountID, UserName, Password from Account where UserName = '" _
& txtuser.Text & "' And Password = '" & txtpass.Text & "'", conn

If Not rs.RecordCount = 0 Then
frmMain.Show
Unload Me
Else
MsgBox "Invalid Input", vbExclamation + vbOKOnly, "Error"
txtpass.Text = ""
txtuser.SetFocus
End If

End Sub

OK Then mark it as solved. However, I don't find the use of

Dim sql As String

so I think it will work without that line.
Thanks

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.