?
Solved

Runtime error 13, while trying to open recordset in access97 DB

Posted on 2003-03-08
15
Medium Priority
?
204 Views
Last Modified: 2011-10-03
I have a Login system on the client side part of a chat program. I have tested and had success with this very same login system on a seperate program.

Private Sub Login_Click()
    Dim db As Database
    Dim rs As Recordset
   
    Set db = OpenDatabase(App.Path & "\siteusers.mdb")
    Set rs = db.OpenRecordset("users")
   
    Do While Not rs.EOF
        If rs.Fields("username") = (txtLogin.Text) And _
        rs.Fields("password") = (txtPassword.Text) Then
       
        Frame2.Visible = False
        Frame1.Visible = False
        txtName.Text = txtLogin.Text
       
        Exit Sub
    Else
        rs.MoveNext
        End If
    Loop
    txtPassword.Text = ""
    MsgBox "Incorrect Password!", vbCritical
End Sub

when i run the program and click Login i recieve the runtime error 13, at:
    Set rs = db.OpenRecordset("users")

any ideas on how to fix this? i am still a novice user of vb, so please explain :)
0
Comment
Question by:jwduke3d
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 3
  • 2
  • +1
15 Comments
 
LVL 2

Expert Comment

by:spauljoseph
ID: 8094222
Place the Database initializing code in the Form_Load() Event of your form. And Globally declare the db and rs variables. (Globally means, place declarations of these variables in the top most first line of your code window)

Now, open the database and recordset in the form_load event and in the Login_Click event just place the code as below:


rs.MoveFirst

Do while rs.EOF<>True
    'Your Code Here
Loop


I hope it can now run.
0
 

Author Comment

by:jwduke3d
ID: 8094272
spauljoseph, when i do it as you have said i get a runtime error 91 on rs.MoveFirst ...
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8094411
is your db/table empty?
if so, there is no first record.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jwduke3d
ID: 8094889
no, it has 70+ users in it
0
 
LVL 1

Accepted Solution

by:
vbaRookie earned 225 total points
ID: 8096352
what references do you have set?
0
 

Author Comment

by:jwduke3d
ID: 8097425
vb for applications
vb runtime objects and procedures
vb objects and procedures
OLE automation
M$ Data Enviroment Instance 1.0
M$ DAO 3.51 Object Library
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8097750
try this little modification:
Private Sub Login_Click()
   Dim db As Database
   Dim rs As Recordset
   
   Set db = dbengine.workspaces(0).OpenDatabase(App.Path & "\siteusers.mdb",false,false)
   Set rs = db.OpenRecordset("users")

and i think you don't need a Do..Loop, just use .findfirst method to locate desired record.
   
   
0
 

Author Comment

by:jwduke3d
ID: 8098090
I still get the  runtime error 13 on  Set rs = db.OpenRecordset("users")
0
 

Author Comment

by:jwduke3d
ID: 8098121
I still get the  runtime error 13 on  Set rs = db.OpenRecordset("users")
0
 
LVL 1

Expert Comment

by:vbaRookie
ID: 8098202
would this help, not sure?

dim rs as dao.recordset
set rs=new dao.recordset

the rest of the code should work fine then
0
 

Author Comment

by:jwduke3d
ID: 8098759
no success with that :(
0
 

Author Comment

by:jwduke3d
ID: 8099325
I have fix my own problem at this point :) their was a conflict with the refrences i had, now i am up and running thats so much for all the help you guys tried to give me
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8102237
I think what vbRookie saids has to be with your problem.
0
 

Author Comment

by:jwduke3d
ID: 8107058
I agree :)
0
 

Author Comment

by:jwduke3d
ID: 8107062
good thinking, made me think.. and it did the trick!
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question