473,386 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

RecordSet Creation Problem

HKM
Hello,

I have a query engine that builds the SQL Query to obtain the
recordSet. Following is an Exmaple Query that my QueryBuilder
outputted

SELECT * FROM BookInfo WHERE BookName LIKE '*cobol*'

When I use this query to build recordset I get empty recordSet back
when the BookInfo table has entries that qualify for this criteria. To
add to it, if I execute this query seperately under MS ACCESS Query
Menu, it works fine. It gives me a perfect output.

Does anyone know why this should happen ?

I'm using Microsoft.Jet.OLEDB.4.0 as my provider and access database
is locally stored.

Thanks in advance,

-HKM
Nov 12 '05 #1
6 3695
TC
Show us the code!

TC
"HKM" <hk****@yahoo.com> wrote in message
news:44**************************@posting.google.c om...
Hello,

I have a query engine that builds the SQL Query to obtain the
recordSet. Following is an Exmaple Query that my QueryBuilder
outputted

SELECT * FROM BookInfo WHERE BookName LIKE '*cobol*'

When I use this query to build recordset I get empty recordSet back
when the BookInfo table has entries that qualify for this criteria. To
add to it, if I execute this query seperately under MS ACCESS Query
Menu, it works fine. It gives me a perfect output.

Does anyone know why this should happen ?

I'm using Microsoft.Jet.OLEDB.4.0 as my provider and access database
is locally stored.

Thanks in advance,

-HKM

Nov 12 '05 #2
HKM
Here is the code..

' Code Get the connection
Public Function GetDBConnection(FileName As String) As
ADODB.Connection
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
FileName
Set GetDBConnection = conn
End Function

' code to generate the record Set from query
Public Function GetRecordSetUsingQuery(Query As String) As
ADODB.recordSet
Dim conn As ADODB.Connection
Dim recordSet As ADODB.recordSet
Set conn = GetDBConnection("E:\temp\db1.mdb")
Set recordSet = New ADODB.recordSet
recordSet.Open Query, conn, adOpenDynamic, adLockOptimistic
Set GetRecordSetUsingQuery = recordSet
End Function

-- Code above is a part of common module that is used by all the
forms.

Following is the Part of Query builder.

Dim Criteria AS String
Criteria = "SELECT * FROM BookInfo WHERE "

If BookNameCheck.Value = True And IsNull(BookNameBox.Value) = False
Then
Criteria = " BookName Like '*" & BookNameBox.Value & "*'"
cnt = cnt + 1
End If
If AuthorNameCheck.Value = True And IsNull(AuthorNameBox.Value) =
False Then
If cnt > 0 Then
Criteria = Criteria & " AND "
End If
Criteria = Criteria & " AuthorName Like '*" & AuthorNameBox.Value
& "*'"
cnt = cnt + 1
If CategoryIDCheck.Value = True AND IsNull(CategoryBox.Value) = False
Then
If cnt > 0 Then
Criteria = Criteria & " AND "
End If
Criteria = Criteria & " CategoryID = " & CategoryBox.Value + 1
cnt = cnt + 1
End If

<snip for other other searchable parameters>

Dim rs As ADODB.recordSet
Set rs = Search.GetRecordSetUsingQuery(Criteria)
If rs.EOF = True Then
MsgBox "Search Did Not Retrieve Any Results", vbInformation, "Book
Search"
Else
DoCmd.OpenForm "SearchResults", , , , acFormReadOnly, acDialog,
Criteria
End If

Down here it always get empty recordset back for the queries that are
using *LIKE* but if I just include Criteria it will build following
query
SELECT * FROM BookInfo WHERE CategoryID = 1 and this works fine. I
dont understand why it doesnt work the same way when my query is using
LIKE.

Thanks
-HKM

"TC" <a@b.c.d> wrote in message news:<1068001298.293023@teuthos>...
Show us the code!

TC
"HKM" <hk****@yahoo.com> wrote in message
news:44**************************@posting.google.c om...
Hello,

I have a query engine that builds the SQL Query to obtain the
recordSet. Following is an Exmaple Query that my QueryBuilder
outputted

SELECT * FROM BookInfo WHERE BookName LIKE '*cobol*'

When I use this query to build recordset I get empty recordSet back
when the BookInfo table has entries that qualify for this criteria. To
add to it, if I execute this query seperately under MS ACCESS Query
Menu, it works fine. It gives me a perfect output.

Does anyone know why this should happen ?

I'm using Microsoft.Jet.OLEDB.4.0 as my provider and access database
is locally stored.

Thanks in advance,

-HKM

Nov 12 '05 #3
hk****@yahoo.com (HKM) wrote in message news:<44**************************@posting.google. com>...
Here is the code..

' Code Get the connection
.......
Dim Criteria AS String
Criteria = "SELECT * FROM BookInfo WHERE "

If BookNameCheck.Value = True And IsNull(BookNameBox.Value) = False
Then
hkm, ******** I think in the next line after = " Criteria &" is missing
Criteria = " BookName Like '*" & BookNameBox.Value & "*'"
cnt = cnt + 1
End If
If AuthorNameCheck.Value = True And IsNull(AuthorNameBox.Value) =


......
Marc
Nov 12 '05 #4
HKM
Yeah, It was a typo. Thats not the problem because i would've got
syntax error for query execution but I'm getting null record set back.

-HKM

M.***********@uva.nl (Marc) wrote in message news:<ae**************************@posting.google. com>...
hk****@yahoo.com (HKM) wrote in message news:<44**************************@posting.google. com>...
Here is the code..

' Code Get the connection


......
Dim Criteria AS String
Criteria = "SELECT * FROM BookInfo WHERE "

If BookNameCheck.Value = True And IsNull(BookNameBox.Value) = False
Then


hkm, ******** I think in the next line after = " Criteria &" is missing
Criteria = " BookName Like '*" & BookNameBox.Value & "*'"
cnt = cnt + 1
End If
If AuthorNameCheck.Value = True And IsNull(AuthorNameBox.Value) =


.....
Marc

Nov 12 '05 #5

"HKM" <hk****@yahoo.com> wrote in message
news:44**************************@posting.google.c om...
Yeah, It was a typo. Thats not the problem because i would've got
syntax error for query execution but I'm getting null record set back.

-HKM

M.***********@uva.nl (Marc) wrote in message

news:<ae**************************@posting.google. com>...
hk****@yahoo.com (HKM) wrote in message news:<44**************************@posting.google. com>...
Here is the code..

' Code Get the connection


......
Dim Criteria AS String
Criteria = "SELECT * FROM BookInfo WHERE "

If BookNameCheck.Value = True And IsNull(BookNameBox.Value) = False
Then


hkm, ******** I think in the next line after = " Criteria &" is missing
Criteria = " BookName Like '*" & BookNameBox.Value & "*'"
cnt = cnt + 1
End If
If AuthorNameCheck.Value = True And IsNull(AuthorNameBox.Value) =


.....
Marc


If you are using ADO you will need to use % instead of *

PS make sure that your code does not explode if BookNameBox.Value has an
apostrophe in it, e.g.
Billy's Bike Book
Fletcher
Nov 12 '05 #6
TC
Sorry, I don't know ADO. But Fletcher's suggestion sounds good to me.

TC
(snip)

Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bryan Harrington | last post by:
Hello all.. I'm working on an application that has a worklist of items for users to work on. I'd like to, based on user security, to filter a worklist based on between 1 and 8 items (i.e.,...
14
by: deko | last post by:
For some reason this does not seem to be working... Am I missing something basic? Dim rst As DAO.Recordset Dim db As DAO.Database Set db = CurrentDb Set rst = db.OpenRecordset("qryEmailS") '...
2
by: Patrick Gonzalez | last post by:
Is it possible to use the built-in filter functions (ie. "Filter by Selection", etc..) when a form's recordsource has been set to a recordset object during the load event. When I try to do this, I...
2
by: Peter Bailey | last post by:
I have tested two queries in the query grid and want to create a dynamic string in vba and then create one recordset that returns the same but cannot quite get my head around one sql string that...
6
by: lenny | last post by:
Hi, I've been trying to use a Sub or Function in VBA to connect to a database, make a query and return the recordset that results from the query. The connection to the database and the query...
36
by: kjvt | last post by:
Based on a prior posting, I've written a function to convert a recordset to a dataview. The first call to the function for a given recordset works perfectly, but the second call always returns a...
10
by: Roger Withnell | last post by:
I'm using ASP, VBScript and SQL Server. I'm also using UTF-8 character set and so my codepage is 65001 and SQL Server datatype nvarchar. I can insert unicode characters correctly into the...
0
by: =?Utf-8?B?UmFodnlu?= | last post by:
I am working on a COM dll in C# that needs to pass an ADODB recordset back to the calling VBScript. I believe I have everthing setup correctly, as the calls work, and it looks like a recordset is...
7
by: tnjarrett | last post by:
Hello, I have a MS Access continuous subform that was using a query as the recordsource. I changed it to use a recordset instead because when the query was used, the changes to the subform values...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.