473,663 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OpenRecordSet ...

I'm trying to create a recordset using "currentDB.Open RecordSet", using a
query as the
"source" string (the only parameter: so all the others are set to their
defaults which, I believe,
means the recordset returned will be a "table" one), but VB keeps giving me
"type mismatch" errors. Should this problem be resolved by changing the
"options" parameter
so that a compatible recordset will be returned, thus eliminating the error?

Thanks,
Russell Potter
Nov 12 '05 #1
8 4797
You'll have to post the actual code for us to really be able to help you.

On Mon, 8 Dec 2003 19:00:03 +1100, "Russell Potter" <rpotter AT iinet DOTnet
DOT au> wrote:
I'm trying to create a recordset using "currentDB.Open RecordSet", using a
query as the
"source" string (the only parameter: so all the others are set to their
defaults which, I believe,
means the recordset returned will be a "table" one), but VB keeps giving me
"type mismatch" errors. Should this problem be resolved by changing the
"options" parameter
so that a compatible recordset will be returned, thus eliminating the error?

Thanks,
Russell Potter


Nov 12 '05 #2
OK then, here's the code in question (that generates the error):
--------------------

Dim r As Recordset
....
Set r = CurrentDb.OpenR ecordset( _
"SELECT Desc as Topic, CategoryName as " & _
"Category, StatusName as Status FROM " & _
"qryTopicsOverv iew")

---------------------

so, as you can see, the "source" string is a/an SQL statement,
which I was thinking might be causing the type mismatch
since, in the absence of a "type" parameter, a "table" type
recordset is created while, if I remember correctly, a/an SQL
statement creates something like a "dynaset" type recordset ...

But am I barking up the right tree here?

Russell

"Steve Jorgensen" <no****@nospam. nospam> wrote in message
news:44******** *************** *********@4ax.c om...
You'll have to post the actual code for us to really be able to help you.

On Mon, 8 Dec 2003 19:00:03 +1100, "Russell Potter" <rpotter AT iinet DOTnet DOT au> wrote:
I'm trying to create a recordset using "currentDB.Open RecordSet", using a
query as the
"source" string (the only parameter: so all the others are set to their
defaults which, I believe,
means the recordset returned will be a "table" one), but VB keeps giving me"type mismatch" errors. Should this problem be resolved by changing the
"options" parameter
so that a compatible recordset will be returned, thus eliminating the error?
Thanks,
Russell Potter

Nov 12 '05 #3
First off, although it is not the cause of the problem you are asking about,
you have a serious problem here in how you are using CurrentDB. CurrentDB is
not a reference to apermanent Database object instance, it is a function that
returns a new database object instance each time it is called. That means
that, by the time you try to read the recordset, it's database instance will
be out of scope, and this can lead to unpreductable results. You shoulr
always assign CurrentDB to a DAO.Database variable before using it, and you
should set DAO object variable references = Nothing in reverse order when yuo
are done with them.

Next, since you are correctly passing a string to the first argument of
OpenRecordset, I suspect that the error might be occurring in the query
itself. To test this, try typing that same SQL into a querydef object, and
running it. There is a clear problem in yur SQL that might or might not be
the cause of your error, but will need to be fixed, and that is that you are
using the SQL keyword, Desc as a column name without putting brackets around
it. I recommend not using that name at all, but if you do, it needs brackets.

So the steps are to first change the Desc column name or putting brackets
around it, then try pasting that directly into a querydef, and seeing if it
runs from there. Finally, I recommend that you make your code look something
like this...

Dim db As DAO.Database
Dim rst As DAO.Recordset
....
Set db = CurrnetDB
Set rst = db.OpenRecordse t( _
"SELECT [Desc] as Topic, CategoryName as " & _
"Category, StatusName as Status FROM " & _
"qryTopicsOverv iew")
...
rst.Close: Set rst = Nothing
Set db = Nothing

On Mon, 8 Dec 2003 19:30:12 +1100, "Russell Potter" <rpotter AT iinet DOTnet
DOT au> wrote:
OK then, here's the code in question (that generates the error):
--------------------

Dim r As Recordset
....
Set r = CurrentDb.OpenR ecordset( _
"SELECT Desc as Topic, CategoryName as " & _
"Category, StatusName as Status FROM " & _
"qryTopicsOverv iew")

---------------------

so, as you can see, the "source" string is a/an SQL statement,
which I was thinking might be causing the type mismatch
since, in the absence of a "type" parameter, a "table" type
recordset is created while, if I remember correctly, a/an SQL
statement creates something like a "dynaset" type recordset ...

But am I barking up the right tree here?

Russell

"Steve Jorgensen" <no****@nospam. nospam> wrote in message
news:44******* *************** **********@4ax. com...
You'll have to post the actual code for us to really be able to help you.

On Mon, 8 Dec 2003 19:00:03 +1100, "Russell Potter" <rpotter AT iinet

DOTnet
DOT au> wrote:
>I'm trying to create a recordset using "currentDB.Open RecordSet", using a
>query as the
>"source" string (the only parameter: so all the others are set to their
>defaults which, I believe,
>means the recordset returned will be a "table" one), but VB keeps givingme >"type mismatch" errors. Should this problem be resolved by changing the
>"options" parameter
>so that a compatible recordset will be returned, thus eliminating theerror? >
>Thanks,
>Russell Potter
>


Nov 12 '05 #4
"Russell Potter" <rpotter AT iinet DOTnet DOT au> wrote in message news:<3f******* *************** @freenews.iinet .net.au>...
I'm trying to create a recordset using "currentDB.Open RecordSet", using a
query as the
"source" string (the only parameter: so all the others are set to their
defaults which, I believe,
means the recordset returned will be a "table" one), but VB keeps giving me
"type mismatch" errors. Should this problem be resolved by changing the
"options" parameter
so that a compatible recordset will be returned, thus eliminating the error?

Thanks,
Russell Potter

Could you post the code, please? There may be (an)other error(s) of
which you are not aware.

Edward
--
The reading group's reading group:
http://www.bookgroup.org.uk
Nov 12 '05 #5
Make sure you have a reference to DAO and then change
Dim r As Recordset
to
Dim r As DAO.Recordset

.... and no you won't get a "table" type recordset from this you'll get a
Dynaset (Dynamic Recordset)
Terry

"Russell Potter" <rpotter AT iinet DOTnet DOT au> wrote in message
news:3f******** **************@ freenews.iinet. net.au...
OK then, here's the code in question (that generates the error):
--------------------

Dim r As Recordset
....
Set r = CurrentDb.OpenR ecordset( _
"SELECT Desc as Topic, CategoryName as " & _
"Category, StatusName as Status FROM " & _
"qryTopicsOverv iew")

---------------------

so, as you can see, the "source" string is a/an SQL statement,
which I was thinking might be causing the type mismatch
since, in the absence of a "type" parameter, a "table" type
recordset is created while, if I remember correctly, a/an SQL
statement creates something like a "dynaset" type recordset ...

But am I barking up the right tree here?

Russell

"Steve Jorgensen" <no****@nospam. nospam> wrote in message
news:44******** *************** *********@4ax.c om...
You'll have to post the actual code for us to really be able to help you.

On Mon, 8 Dec 2003 19:00:03 +1100, "Russell Potter" <rpotter AT iinet DOTnet
DOT au> wrote:
I'm trying to create a recordset using "currentDB.Open RecordSet", using aquery as the
"source" string (the only parameter: so all the others are set to theirdefaults which, I believe,
means the recordset returned will be a "table" one), but VB keeps giving me"type mismatch" errors. Should this problem be resolved by changing
the"options" parameter
so that a compatible recordset will be returned, thus eliminating the

error?
Thanks,
Russell Potter


Nov 12 '05 #6
Steve.

Sorry to sound like such a complete dunce and waste everyone's time,
but the code you gave me to try wouldn't compile because I don't have
a reference to the DAO type library, but I can't add the reference
because, no matter what I do, my "Tools -> references" command
seems to stay permanently disabled.

So .. I was wondering ... under what circumstances would it usually
become enabled?

Thanks,
Russell

"Steve Jorgensen" <no****@nospam. nospam> wrote in message
news:q4******** *************** *********@4ax.c om...
First off, although it is not the cause of the problem you are asking about, you have a serious problem here in how you are using CurrentDB. CurrentDB is not a reference to apermanent Database object instance, it is a function that returns a new database object instance each time it is called. That means
that, by the time you try to read the recordset, it's database instance will be out of scope, and this can lead to unpreductable results. You shoulr
always assign CurrentDB to a DAO.Database variable before using it, and you should set DAO object variable references = Nothing in reverse order when yuo are done with them.

Next, since you are correctly passing a string to the first argument of
OpenRecordset, I suspect that the error might be occurring in the query
itself. To test this, try typing that same SQL into a querydef object, and running it. There is a clear problem in yur SQL that might or might not be the cause of your error, but will need to be fixed, and that is that you are using the SQL keyword, Desc as a column name without putting brackets around it. I recommend not using that name at all, but if you do, it needs brackets.
So the steps are to first change the Desc column name or putting brackets
around it, then try pasting that directly into a querydef, and seeing if it runs from there. Finally, I recommend that you make your code look something like this...

Dim db As DAO.Database
Dim rst As DAO.Recordset
....
Set db = CurrnetDB
Set rst = db.OpenRecordse t( _
"SELECT [Desc] as Topic, CategoryName as " & _
"Category, StatusName as Status FROM " & _
"qryTopicsOverv iew")
...
rst.Close: Set rst = Nothing
Set db = Nothing

On Mon, 8 Dec 2003 19:30:12 +1100, "Russell Potter" <rpotter AT iinet DOTnet DOT au> wrote:
OK then, here's the code in question (that generates the error):
--------------------

Dim r As Recordset
....
Set r = CurrentDb.OpenR ecordset( _
"SELECT Desc as Topic, CategoryName as " & _
"Category, StatusName as Status FROM " & _
"qryTopicsOverv iew")

---------------------

so, as you can see, the "source" string is a/an SQL statement,
which I was thinking might be causing the type mismatch
since, in the absence of a "type" parameter, a "table" type
recordset is created while, if I remember correctly, a/an SQL
statement creates something like a "dynaset" type recordset ...

But am I barking up the right tree here?

Russell

"Steve Jorgensen" <no****@nospam. nospam> wrote in message
news:44******* *************** **********@4ax. com...
You'll have to post the actual code for us to really be able to help you.
On Mon, 8 Dec 2003 19:00:03 +1100, "Russell Potter" <rpotter AT iinet

DOTnet
DOT au> wrote:

>I'm trying to create a recordset using "currentDB.Open RecordSet", using a >query as the
>"source" string (the only parameter: so all the others are set to their >defaults which, I believe,
>means the recordset returned will be a "table" one), but VB keeps giving
me
>"type mismatch" errors. Should this problem be resolved by changing

the >"options" parameter
>so that a compatible recordset will be returned, thus eliminating the

error?
>
>Thanks,
>Russell Potter
>

Nov 12 '05 #7
Oh - the code you originally posted can only work if there is reference to
DAO. Because CurrentDB returns a DAO database instance, but your variable was
an ADO recordset since you didn't have the DAO reference. That doesn't work.

In Access 2000 and newer, by default, only the ADO reference appears in a new
datbase. To get the DAO reference, you have to add it. I don't know why your
Tools -> References is disabled, but it could be that you are trying to access
it when you code is running or stopeed in break mode. Try resetting the code,
and see if that fixes it.

On Tue, 9 Dec 2003 16:40:54 +1100, "Russell Potter" <rpotter AT iinet DOTnet
DOT au> wrote:
Steve.

Sorry to sound like such a complete dunce and waste everyone's time,
but the code you gave me to try wouldn't compile because I don't have
a reference to the DAO type library, but I can't add the reference
because, no matter what I do, my "Tools -> references" command
seems to stay permanently disabled.

So .. I was wondering ... under what circumstances would it usually
become enabled?

Thanks,
Russell

"Steve Jorgensen" <no****@nospam. nospam> wrote in message
news:q4******* *************** **********@4ax. com...
First off, although it is not the cause of the problem you are asking

about,
you have a serious problem here in how you are using CurrentDB. CurrentDB

is
not a reference to apermanent Database object instance, it is a function

that
returns a new database object instance each time it is called. That means
that, by the time you try to read the recordset, it's database instance

will
be out of scope, and this can lead to unpreductable results. You shoulr
always assign CurrentDB to a DAO.Database variable before using it, and

you
should set DAO object variable references = Nothing in reverse order when

yuo
are done with them.

Next, since you are correctly passing a string to the first argument of
OpenRecordset, I suspect that the error might be occurring in the query
itself. To test this, try typing that same SQL into a querydef object,

and
running it. There is a clear problem in yur SQL that might or might not

be
the cause of your error, but will need to be fixed, and that is that you

are
using the SQL keyword, Desc as a column name without putting brackets

around
it. I recommend not using that name at all, but if you do, it needs

brackets.

So the steps are to first change the Desc column name or putting brackets
around it, then try pasting that directly into a querydef, and seeing if

it
runs from there. Finally, I recommend that you make your code look

something
like this...

Dim db As DAO.Database
Dim rst As DAO.Recordset
....
Set db = CurrnetDB
Set rst = db.OpenRecordse t( _
"SELECT [Desc] as Topic, CategoryName as " & _
"Category, StatusName as Status FROM " & _
"qryTopicsOverv iew")
...
rst.Close: Set rst = Nothing
Set db = Nothing

On Mon, 8 Dec 2003 19:30:12 +1100, "Russell Potter" <rpotter AT iinet

DOTnet
DOT au> wrote:
>OK then, here's the code in question (that generates the error):
>--------------------
>
> Dim r As Recordset
> ....
> Set r = CurrentDb.OpenR ecordset( _
> "SELECT Desc as Topic, CategoryName as " & _
> "Category, StatusName as Status FROM " & _
> "qryTopicsOverv iew")
>
>---------------------
>
>so, as you can see, the "source" string is a/an SQL statement,
>which I was thinking might be causing the type mismatch
>since, in the absence of a "type" parameter, a "table" type
>recordset is created while, if I remember correctly, a/an SQL
>statement creates something like a "dynaset" type recordset ...
>
>But am I barking up the right tree here?
>
>Russell
>
>"Steve Jorgensen" <no****@nospam. nospam> wrote in message
>news:44******* *************** **********@4ax. com...
>> You'll have to post the actual code for us to really be able to helpyou. >>
>> On Mon, 8 Dec 2003 19:00:03 +1100, "Russell Potter" <rpotter AT iinet
>DOTnet
>> DOT au> wrote:
>>
>> >I'm trying to create a recordset using "currentDB.Open RecordSet",using a >> >query as the
>> >"source" string (the only parameter: so all the others are set totheir >> >defaults which, I believe,
>> >means the recordset returned will be a "table" one), but VB keepsgiving >me
>> >"type mismatch" errors. Should this problem be resolved by changingthe >> >"options" parameter
>> >so that a compatible recordset will be returned, thus eliminating the
>error?
>> >
>> >Thanks,
>> >Russell Potter
>> >
>>
>


Nov 12 '05 #8

Steve
Oh - the code you originally posted can only work if there is reference to
DAO. Because CurrentDB returns a DAO database instance, but your variable was an ADO recordset since you didn't have the DAO reference. That doesn't

work.

Thanks for that info: I figured out for myself, through some of
experimentation ,
the circumstances under which the "Tools -> References" command becomes
enabled: I just needed, , as you said in your earlier post, to reset the
code. I
hadn't had enough time to do those experiments yesterday before I posted so
prematurely :-).

Once that DAO reference was enabled, and I'd changed the code to
what you had suggested, it compiled fine and, even better, now works
perfectly! ... and getting that recordset populated correctly means my data
now exports beautifully to both Word and Excel, impressing the boss no end,
so thanks!

Russell

Nov 12 '05 #9

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

Similar topics

1
8204
by: el Benno | last post by:
If CurrentDb.OpenRecordset("table").EOF Then ... works fine If CurrentDb.OpenRecordset("Query").EOF Then ... doesn't????????? microsft help is outstanding too - surprise surprise any help greatly appreciated! / Ben
5
17867
by: Philippa | last post by:
I'm trying to access data in vba using the openrecordset command. The data in on a SQL Server 2000 database, and I have linked tables to that data. the Table I'm trying to access is one of these linked tables, and my codes is as follows: Set vRS = CurrentDb.OpenRecordset(tbl_DataCommentLog) when this line is executed I get the error: "Run-time error '3622':
0
5377
by: mo. | last post by:
I need some help in accessing Jet database using DAO. I have just started to learn c# and am trying to rewrite a program I have in vb.net to c#. In VB.Net I can do this: Dim ws As DAO.Workspace Dim db As DAO.Database ws = DAODBEngine_definst.Workspaces(0) db = ws.OpenDatabase(DBFileName) Dim rs As DAO.Recordset
5
19915
by: Sunnyrain | last post by:
I am developing a program in Access 2000. I couldn't make OpenRecordset method work right. It's working when I opened a simple SQL query below in OpenRecordset. ..... Dim dbs As Database, rst As Recordset Set dbs = CurrentDb
0
1923
by: Peter S | last post by:
Hi: I am trying to read a SQL Server text field (Access memo field) using connection.OpenRecordSet("qry with text field") rather than database.OpenRecordSet("qry with text field")
1
10813
by: jnikle | last post by:
I have a parameter query named "qry_employee_info_reports" that I need to run in the OnOpen event of a form. I'm after its total number of records. The query's got several joins in it, and one of them is to query "qry_last_transition," which is also a parameter query. Both querys use the same parameter: a control called "txtSecondDate" on a pop up form. What I've been trying to do up to this point is to open up this parameter form,...
10
3721
by: MLH | last post by:
Gentlemen: I am having one heck of a time taking a DAO walk through the records in an SQL dynaset. I'm trying to walk a set of records returned by a UNION query. I'm attempting to filter the records to those related to vehicle #60 ( = 60 ). If I explicitly specify 60 in the SQL ==everything works fine. Take a look: 100 PString = "SELECT & " & Chr$(&H22) & Space(1) & Chr$(&H22) & " & AS Recipient " 120 PString = PString & "FROM...
22
10275
by: MLH | last post by:
100 Dim db As Database, rst As Recordset 120 Set db = CurrentDb 140 PString = "SELECT qryBatchList.ReadyFor906, qryBatchList.BatchID FROM qryBatchList WHERE qryBatchList.BatchID=GetCurrentBatchID()" 160 Set rst = db.OpenRecordset(PString, dbOpenDynaset) At compile time, things are OK. But at run time, line #160 gives rise to an error saying some FN I've used for years is undefined. It almost seems like it pukes on some random
7
11049
by: mirandacascade | last post by:
The questions are toward the bottom of this post. Situation is this: 1) Access 97 2) Multi-user appplication 3) SQL Server 2000 4) Sporadically (i.e. less than 1% of the time) encounter the following error: 3218 Couldn't update; currently locked
0
8435
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8547
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1754
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.