Dim con As New ADODB.Command
Dim rs As New ADODB.Recordset
Private Sub cmdcancel_Click()
Unload Me
End Sub
Private Sub cmdLogin_Click()
Set rspassword = New ADODB.Recordset
rspassword.Open "Select * from table1"
If rspassword.RecordCount > 0 Then
Do Until rspassword.EOF
If txtUsername.Text = rspassword!UserName And txtPassword.Text = rspassword!Password Then
'frmmain.L1.Caption = Text1.Text
Set rspassword = Nothing
Unload Me
frmmain.Show
ctr = 0
Exit Do
Else
rspassword.MoveNext
ctr = ctr + 1
End If
Loop
If ctr > 0 Then
Set rspassword = Nothing
MsgBox "Invalid!", vbExclamation
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
ctr = 0
End If
End If
End Sub
connection cannot be used
Page 1 of 16 Replies - 536 Views - Last Post: 30 August 2012 - 08:44 PM
#1
connection cannot be used
Posted 12 August 2012 - 04:33 AM
this is my code for the login form using ms access would someone please help me? Everytime I run the program, it usually says connection cannot be used.
Replies To: connection cannot be used
#2
Re: connection cannot be used
Posted 12 August 2012 - 05:21 AM
Where do you open the connection to the database?
#3
Re: connection cannot be used
Posted 12 August 2012 - 05:53 AM
maj3091, on 12 August 2012 - 05:21 AM, said:
Where do you open the connection to the database?
Public rs As New ADODB.Recordset
Public con As New ADODB.Connection
Public Sub OpenCon()
Set con = New ADODB.Connection
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\Database\enrollment.mdb"
#4
Re: connection cannot be used
Posted 12 August 2012 - 09:01 AM
Please don't PM me on open threads, keep things in the forum.
Does the connection open OK? Do you check it's actually open?
Does the connection open OK? Do you check it's actually open?
#5
Re: connection cannot be used
Posted 12 August 2012 - 05:40 PM
yes he opened it but where is he assigned the connection to the recordset
#6
Re: connection cannot be used
Posted 13 August 2012 - 12:12 AM
thava, on 13 August 2012 - 01:40 AM, said:
yes he opened it but where is he assigned the connection to the recordset
Well spotted thava....you can tell I don't do much database work!
Have a look a the Recordset properties and methods.
You either need to set the ActiveConnection property, or pass it during your .Open call.
#7
Re: connection cannot be used
Posted 30 August 2012 - 08:44 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|