-
March 8th, 2011, 06:33 PM
#1
[RESOLVED] I NEED HELP!!! DAO Recordset Problem
I am getting really MAD now. It's been Hours that I am working on this and searching on google for anything but No answer!!!
Can someone please tell me how to Do a search using Dao Recordset like we do in VB6? Here is the code I have in a module
Code:
Public WS as dao.Workspace
Public DB as dao.Database
Public RS as dao.Recordset
Public Sub SearchInDatabase(ByVal sSearch as string)
Dim sSQL As String
...
DB = WS.OpenDatabase("{MDB_FilePath}")
sSQL = "SELECT * FROM {Table} WHERE {FieldName} LIKE '*{Value}*'"
RS = DB.OpenRecordset(sSQL)
Do While Not RS.EOF
...
Loop
...
End Sub
Here is my problem. The databse is opened correctly but when it comes to the line RS = DB.OpenRecordset it tells me that I need to create a New instance of the object RS. HOW DO WE DO THAT!!!!
I'm sorry for the capitals but after hours of search and head scratching I gave up and posted here!
Please, someone help me! AND NO, I don't want to use ADO or any other. I want to know how to use DAO like VB6!
Thank you in advance for your help!
David Richard
-
March 8th, 2011, 07:08 PM
#2
Re: I NEED HELP!!! DAO Recordset Problem
How about this?
Code:
Public RecSet as dao.Recordset,RS as dao.Recordset
RS= NEW RecSet
Also, put this in the VB6 FORUM next time, if that's what it is.
DAO is very old. Why work with it at all? ADO is preferred
Last edited by dglienna; March 8th, 2011 at 07:11 PM.
-
March 8th, 2011, 10:02 PM
#3
Re: I NEED HELP!!! DAO Recordset Problem
I'm using VB.NET and I want an answer for VB.NET. Why would I put this in VB6 forums???
I'll give feed back after trying your suggestion. Thank's for your answer.
David Richard
-
March 8th, 2011, 10:46 PM
#4
Re: I NEED HELP!!! DAO Recordset Problem
I don't know why you don't use ADO, as there is support built in.
Code:
Dim RS = New dao.Recordset
VB.Net lets you assign during a DIM, so you can use that, if it's even allowed
-
March 9th, 2011, 01:00 AM
#5
Re: I NEED HELP!!! DAO Recordset Problem
I have to agree with David here. Dao is very old, and support for it is dying in .NET.
ADO.NET is the preferred way to handle databases in .NET
-
March 9th, 2011, 01:11 AM
#6
Re: I NEED HELP!!! DAO Recordset Problem
Agreed DAO has been dead for years. I don't think I have used this in at least 10 years now.
Use ADO instead.
DAO btw is not VB6 either it is VB5 and older. VB6 uses ADO. You will also find that getting the proper run time files to get DAO to work on the end users machine can be rather difficult now.
Always use [code][/code] tags when posting code.
-
March 9th, 2011, 07:59 AM
#7
-
March 9th, 2011, 08:21 AM
#8
Re: I NEED HELP!!! DAO Recordset Problem
OK, common sense tells me not to do what I'm about to, but yeah, we are here to try and help and guide wherever possible.
Because our guidence and advice didn't seem to "help" you much, let's do a test. Upload your project in zip format here, and we could perhaps have a look at it, and take it from there...
-
March 9th, 2011, 10:09 AM
#9
Re: I NEED HELP!!! DAO Recordset Problem
For security issues I connot post my project but I have good news. I figured out what the problem was so I'm going to post the solution here for those that still use DAO. I really thank everyone for trying to help me even though I'm way behind with my DAO.
The initial problem was not my RS = DB.OpenRecordset even though VB pointed the error there. NO, the error was on the DB = WS.OpenDatabase.
I removed Public WS As dao.WorkSpace and replaced it with Public EN as dao.DBEngine.
Now My code looks like this when I open my database.
Code:
Public sub OpenDatabase(ByVal DBPath As String)
EN = New dao.DBEngine
DB = EN.OpenDatabase(DBPath)
End Sub
Now I can Use RS = DB.OpenRecordset any time without creating a new instance of whatever. Here is the sample code:
Code:
Public Sub SearchDatabase(ByVal sSearch As String)
...
sSQL = "SELECT * FROM {TableName} WHERE {FieldName} LIKE '*{Value}*'"
RS = DB.OpenRecordset(sSQL)
Do While Not RS.EOF
LstResults.Items.Add(RS.Fields("{FieldName}").Value)
RS.MoveNext()
Loop
...
End Sub
Again thanks for your time and support. I love CodeGuru and those that help me out. I hope this will help others out if needed. And for my further programs, I'll work with ADO since it seems that not many people like it anymore and almost no support is given.
Again thanks a lot!
David Richard
-
March 9th, 2011, 11:14 AM
#10
Re: [RESOLVED] I NEED HELP!!! DAO Recordset Problem
Thanks for sharing! I'm glad you have sorted it out
Tags for this Thread
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
|