|
-
April 1st, 2011, 04:22 PM
#1
Help on Run - time error 91
Hi guys. I just wanted to ask you help in this tricky little thingy. I'm trying to create a log in action which takes the username and password from an access .mdb file and verifies it with the ones entered in a text box. but somehow I seem to be getting a Run - time error 91 (Object variable or With block variable not set)
The code is as below and the problematic line of coding has been highlighted.
Code:
Private Sub login_btn_Click()
Set rs = db.OpenRecordset("Select emp_username from employee where emp_username = '" & username_txt.Text & "'")
If Not rs.RecordCount = 0 Then
Set rs = db.OpenRecordset("Select emp_pass from employee where emp_pass = '" & password_txt.Text & "'")
If Not rs.RecordCount = 0 Then
login_frame.Visible = False 'hide login frame
welcome_frame.Visible = True 'unhide welcome frame
btn_home.Visible = False 'unhide buttons
btn_rent_car.Visible = False
btn_customer.Visible = False
btn_car.Visible = False
btn_account.Visible = False
btn_employee.Visible = False
Else
MsgBox "Password incorrect"
password_txt.SetFocus
End If
Else
MsgBox "Username incorrect"
username_txt.SetFocus
End If
End Sub
I have added a reference to the ADO and also created a module which goes like this
Code:
Public rs As DAO.Recordset
Public db As DAO.Database
Public Sub Main()
Set db = OpenDatabase(App.Path + "/EasyRent.mdb")
main_form.Show
End Sub
I'm still doing my diploma so any help at all would be greatly appreciated. Thanking you guys i advance.
-
April 1st, 2011, 05:40 PM
#2
Re: Help on Run - time error 91
Take a look at this article, and the attached sample. It shows how to open a connection and query a table.
-
April 3rd, 2011, 05:36 PM
#3
Re: Help on Run - time error 91
Erm... you were saying, you are referring to the ADO, but making use od DAO objects?
-
April 3rd, 2011, 11:41 PM
#4
Re: Help on Run - time error 91
Thanks to dglienna. it really is a very informative post. But by doing that I would have to change the entire structure of my coding. So I' keeping that as a last resort. Thank you very, very much. at least I have a plan B 
To WoF sorry. I was kinda confused DAO with ADO. I put a reference for DAO actually. Truly sorry for confusing you. Do you know why I'm having this problem? Any help would be greatly appreciated
-
April 3rd, 2011, 11:43 PM
#5
Re: Help on Run - time error 91
Depends on where you expect to be able to install and run it. Might not have old references available for x64 Windows 7 / Windows Server 2008 R2
-
April 3rd, 2011, 11:50 PM
#6
Re: Help on Run - time error 91
Sorry dglienna. But could you kinda like explain that. I'm trully sorry for bothering you with this trivial question. But I'm using an x64 Windows 7. Do you think that's the reason why I'm getting this error during run time?
-
April 4th, 2011, 10:52 AM
#7
Re: Help on Run - time error 91
Well, my code runs on x64, if that's what you mean. Might now have DAO either, as that is old
-
April 4th, 2011, 12:48 PM
#8
Re: Help on Run - time error 91
Looks like the problem is that the database object referred to by 'db' hasn't been opened. The fact it is coming up with error 91 means that db has been defined as a database but either hasn't been opened or has been closed.
Normally with access DAO you would use someting like...
Code:
Set db = OpenDatabase("c:\dbname.mdb")
Also I would point out that if you are using DAO to link to an Access database then try to avoid using the RecordCount property as this can be inaccurate if there are deleted records in the table.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|