Computing.Net > Forums > Office Software > MS Access 2000 Recordset Issues

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

MS Access 2000 Recordset Issues

Reply to Message Icon

Name: Orias Tait
Date: September 12, 2003 at 06:37:10 Pacific
OS: Windows 98 SE
CPU/Ram: PII/198.0 MB
Comment:

I am attempting to use a recordset in MS Access 2000. I have a function that I copied from an Access 97 database, that worked before:

Private Function Get_Count() As Integer
Dim TempSet As Recordset ' The results to return
My_SQL = "SELECT Count(*) AS Record_Count " & _
"FROM DWGPS_Wrk_Hrs_Prj"

Set TempSet = CurrentDb.OpenRecordset(My_SQL)

Get_Max_ID = TempSet.Fields("Record_Count").Value

TempSet.Close
End Function ' Get_Count

The variable My_SQL is a global string.

The problem is that for MS Access 2000, this same code generates the error "Type mismatch". All of the help files indicate I should create a temporary variable of type Database, however the compiler does not understand that data type.

What am I doing wrong?

Thanks,

Orias Tait




Sponsored Link
Ads by Google

Response Number 1
Name: A Certain TH
Date: September 12, 2003 at 07:56:52 Pacific
Reply:

Try:

Dim cDatabase as DAO.Database
Dim Tempset as DAO.Recordset

Set cDatabase as Currentdb

Then when you try to execute the sql, use:

Set Tempset = cDatabase.OpenRecordset(My_SQL)


Hope that sorts it out for you
Tom


0

Response Number 2
Name: orias
Date: September 16, 2003 at 12:48:01 Pacific
Reply:

Tom,

I attempted to use your example, and I received the following errors:

1. Set cDatabase as Currentdb needed to be re-written as Set cDatabase = CurrentDb for it to be accepted by the code validation
2. When attempting to run the function, execution stopped at Dim cDatabase As DAO.Database with the error message: “User-defined type not defined”.

Is it possible I do not have a required library function installed or something? I took all options when I upgraded to Access 2000.

My function now looks like this:

Private Function Get_Count() As Integer

Dim cDatabase As DAO.Database
Dim TempSet As DAO.Recordset

Set cDatabase = CurrentDb
My_SQL = "SELECT Count(*) AS Record_Count " & _
"FROM DWGPS_Wrk_Hrs_Prj"

Set TempSet = cDatabase.OpenRecordset(My_SQL)

Get_Max_ID = TempSet.Fields("Record_Count").Value

' Cleanup Environment
TempSet.Close
End Function ' Get_Count

Thanks,

Orias Tait


0

Response Number 3
Name: A Certain TH
Date: September 17, 2003 at 01:31:59 Pacific
Reply:

What references do you have ticked?

The above works for me, and I have:

1) VBA
2) MS Access 9.0 Object Library
3) OLE Automation
4) MS ActiveX Data Objects 2.1 Library

Tom


0

Response Number 4
Name: orias
Date: September 24, 2003 at 09:09:54 Pacific
Reply:

Taking your suggestion, I examined the difference in References between the 97 database and the 2000 database. What I found was the following was not referenced in the 2000 database:

Microsoft Visual Basic for Applications Extensibility 5.3

After adding that, I received the same error with the code. I then re-examined the “help” entry for OpenRecordset. The first parameter, source, is supposed to be a string specifying the source of the records for the recordset. The source can be a table name, a query name or an SQL Statement that returns records.

Seeing the word “String”, I decided to use the standard VB String identifier of quotation marks. Thus my call was as follows:

Set TempSet = CurrentDb.OpenRecordset("My_SQL")

The error returned was:

The Microsoft Jet database engine cannot find the input table or query ‘My_SQL’. Make sure it exists and that its name is spelled correctly.

To verify my suspicions, I hard coded the SQL into the function call:

Set TempSet = CurrentDb.OpenRecordset("SELECT Count(*) AS Serial_Count FROM DWGPS_Wrk_Hrs_Prj")

The error returned was:

Type mismatch

In 97, I was using this to dynamically create my SQL, then passing it onto OpenRecordset. In 2000, it appears that you can no longer do this. I have not attempted to dynamically create a query using the dynamically created SQL, I wanted to find out the following:

1. Am I looking at this correctly? Has the way Access is utilizing OpenRecordset changed into another undocumented feature not allowing for direct SQL?
2. Is there something I am missing, or will I have to create either a temporary query or table to use with OpenRecordset?

Thanks,

Orias Tait


0

Response Number 5
Name: Enrique_Saavedra
Date: September 24, 2003 at 14:51:04 Pacific
Reply:

Try

Use the DAO Object Library reference instead of ADO Object Library.

The Database object is a DAO object, so you have to reference the correct object library because Access 2000 uses by default the ADO object Library.

Hope this will be usefull,
Enrique


0

Related Posts

See More



Response Number 6
Name: orias
Date: September 25, 2003 at 06:24:15 Pacific
Reply:

I added the References (individually, as they conflicted with each other):

Microsoft DAO 2.5/3.51 Compatibility Library
Microsoft DAO 3.5 Object Library
Microsoft DAO 3.6 Object Library

and recieved the same error:

Type mismatch

Thanks,

Orias Tait


0

Response Number 7
Name: Enrique_Saavedra
Date: September 25, 2003 at 08:59:18 Pacific
Reply:

I have tested this function and is working fine:

Private Function Get_Count() As Integer
Dim TempSet As DAO.Recordset ' The results to return
My_SQL = "SELECT Count(*) AS Record_Count " & _
"FROM [Table_Name]"

Set TempSet = CurrentDb.OpenRecordset(My_SQL)

Get_Count = TempSet.Fields("Record_Count").Value

TempSet.Close
End Function ' Get_Count

You have to reference the Microsoft DAO Object Library.

The error Data Type mismatch is because when you declare a Recordset variable, by default is an ADO.Recordset and you cannot assign a value to that type of variable with CurrentDb.OpenRecordset so change the declaration to explicit tell VB that you want to use a DAO.Recordset object but remember that you must reference the DAO Library.

In the other hand, there was an error in the code. When you programa a Function, the result must be assigned to a "variable" with the function's name:
Get_Count = TempSet.Fields("Record_Count").Value
instead of Get_Max_ID = TempSet.Fields("Record_Count").Value

Try these changes and let me know they work.
Enrique


0

Response Number 8
Name: orias
Date: October 1, 2003 at 12:21:40 Pacific
Reply:

Enrique,

Thanks. What appeared to be missing was the "DAO." infront of the Recordset declaration. Once that was added, the function worked as expected.

I am a bit confused because the objects for DOA indicate:

RecordsetOptionEnum
RecordsetTypeEnum

There is no option for "Recordset". Why is the VB Interpreter accepting what appears to be a user defined object?

Thanks,

Orias


0

Response Number 9
Name: Enrique_Saavedra
Date: October 6, 2003 at 10:57:35 Pacific
Reply:

When you open a DAO.Recordset, you may specify the Type, Options and Locks so you can use the following constants for Type:
DAO.Recordset.TypeEnum.dbOpenDynamic or just dbOpenDynamic, dbOpenDynaset,
dbOpenForwardOnly, dbOpenSnapShot or dbOpenTable.

There are other constants you can use for Options and Locks too. You should consult Access Help (Index: recordset) to learn detailed information about constants (e.g., dbOpenDynaset and adOpenStatic).

Cheers,
Enrique


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: MS Access 2000 Recordset Issues

MS Access 2000 www.computing.net/answers/office/ms-access-2000/2151.html

printer object in MS access www.computing.net/answers/office/printer-object-in-ms-access/1576.html

Access 2000 CUMIPMT Function www.computing.net/answers/office/access-2000-cumipmt-function/611.html