sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
darkforcesjedi's Avatar

DAO Connectionless Recordset?


Question posted by: darkforcesjedi (Guest) on July 17th, 2006 04:45 PM
Creating a connectionless recordset in ADO is simple enough, but how do
you do it in DAO? I want a recordset stored in memory so I can
filter/sort it easily. If I create a table I can make it work, but I
don't want to have to read/write everything from/to disk every time I
need to use the data.

I tried:

Dim r As DAO.Recordset, tdf As DAO.TableDef

Set tdf = CurrentDb.CreateTableDef("tmp", dbHiddenObject)
With tdf.Fields
.Append tdf.CreateField("TypeID", dbLong)
.Append tdf.CreateField("Minor_ID", dbLong)

End With

'ERROR 3420 "Object invalid or no longer set"
Set r = tdf.OpenRecordset

r.AddNew
r.Fields("TypeID") = 1
r.Fields("Minor_ID") = 7
r.Update

r.Close
Set r = Nothing
Set tdf = Nothing

4 Answers Posted
Lyle Fairfield's Avatar
Lyle Fairfield July 17th, 2006 05:05 PM
Guest - n/a Posts
#2: Re: DAO Connectionless Recordset?


darkforcesjedi wrote:
Quote:
Originally Posted by
Creating a connectionless recordset in ADO is simple enough, but how do
you do it in DAO? I want a recordset stored in memory so I can
filter/sort it easily. If I create a table I can make it work, but I
don't want to have to read/write everything from/to disk every time I
need to use the data.
>
I tried:
>
Dim r As DAO.Recordset, tdf As DAO.TableDef
>
Set tdf = CurrentDb.CreateTableDef("tmp", dbHiddenObject)
With tdf.Fields
.Append tdf.CreateField("TypeID", dbLong)
.Append tdf.CreateField("Minor_ID", dbLong)
>
End With
>
'ERROR 3420 "Object invalid or no longer set"
Set r = tdf.OpenRecordset
>
r.AddNew
r.Fields("TypeID") = 1
r.Fields("Minor_ID") = 7
r.Update
>
r.Close
Set r = Nothing
Set tdf = Nothing

Quote:
Originally Posted by
>From many years ago (the notion is that Transactions will make this

recordset never saved to disk):

Function VirtualDAORecordSet()
Dim TableName As String
Dim Counter As Long
Dim Rcs As DAO.Recordset
With DBEngine
.BeginTrans
With .Workspaces(0)(0)
On Error GoTo CreateTableErr:
TableName = "tblTemp" & CStr(Counter)
.Execute "CREATE TABLE " & TableName & "(fldHoliday TEXT
CONSTRAINT AlphaHoliday UNIQUE);"
Set Rcs = .OpenRecordset(TableName, dbOpenTable)
With Rcs
.AddNew
.Fields("fldHoliday") = "Xerxes Day"
.Update
.AddNew
.Fields("fldHoliday") = "Anaximander Day"
.Update
.AddNew
.Fields("fldHoliday") = "Plato Day"
.Update
.Index = "AlphaHoliday"
.MoveFirst
MsgBox .Fields("fldHoliday") 'Anixamder Day
.MoveNext
MsgBox .Fields("fldHoliday") 'Plato Day
.MoveLast
MsgBox .Fields("fldHoliday") 'Xerxes Day
.Close
End With
End With
End With
VirtualDAORecordSetExit:
Set Rcs = Nothing
DBEngine.Rollback
Exit Function
CreateTableErr:
With Err
If .Number = 3010 Then
Counter = Counter + 1
TableName = "tblTemp" & CStr(Counter)
Resume
Else
MsgBox .Number & " " & .Description
Resume VirtualDAORecordSetExit
End If
End With
End Function

David W. Fenton's Avatar
David W. Fenton July 18th, 2006 12:15 AM
Guest - n/a Posts
#3: Re: DAO Connectionless Recordset?

"darkforcesjedi" <andrew.mallner@pgnmail.comwrote in
news:1153151508.366449.151670@m73g2000cwd.googlegr oups.com:
Quote:
Originally Posted by
Creating a connectionless recordset in ADO is simple enough, but
how do you do it in DAO?


No. Disconnected recordsets do not exist in DAO and probably never
will. You have to use a table or a transaction (on real tables that
is then rolled back).

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Tom van Stiphout's Avatar
Tom van Stiphout July 18th, 2006 03:55 AM
Guest - n/a Posts
#4: Re: DAO Connectionless Recordset?

On 17 Jul 2006 09:05:10 -0700, "Lyle Fairfield"
<lylefairfield@aim.comwrote:

Anaximander? That's kind-a obscure. Scolars don't even agree on his
birth year, let alone birth date. And no women in the list (or did you
just provide a fragment of your code)?
Your transaction idea is just as obscure. It probably works, but would
you want it to?

-Tom.

Quote:
Originally Posted by
>
>darkforcesjedi wrote:
Quote:
Originally Posted by
>Creating a connectionless recordset in ADO is simple enough, but how do
>you do it in DAO? I want a recordset stored in memory so I can
>filter/sort it easily. If I create a table I can make it work, but I
>don't want to have to read/write everything from/to disk every time I
>need to use the data.
>>
>I tried:
>>
> Dim r As DAO.Recordset, tdf As DAO.TableDef
>>
> Set tdf = CurrentDb.CreateTableDef("tmp", dbHiddenObject)
> With tdf.Fields
> .Append tdf.CreateField("TypeID", dbLong)
> .Append tdf.CreateField("Minor_ID", dbLong)
>>
> End With
>>
> 'ERROR 3420 "Object invalid or no longer set"
> Set r = tdf.OpenRecordset
>>
> r.AddNew
> r.Fields("TypeID") = 1
> r.Fields("Minor_ID") = 7
> r.Update
>>
> r.Close
> Set r = Nothing
> Set tdf = Nothing

>
Quote:
Originally Posted by
>>From many years ago (the notion is that Transactions will make this

>recordset never saved to disk):
>
>Function VirtualDAORecordSet()
Dim TableName As String
Dim Counter As Long
Dim Rcs As DAO.Recordset
With DBEngine
.BeginTrans
With .Workspaces(0)(0)
On Error GoTo CreateTableErr:
TableName = "tblTemp" & CStr(Counter)
.Execute "CREATE TABLE " & TableName & "(fldHoliday TEXT
>CONSTRAINT AlphaHoliday UNIQUE);"
Set Rcs = .OpenRecordset(TableName, dbOpenTable)
With Rcs
.AddNew
.Fields("fldHoliday") = "Xerxes Day"
.Update
.AddNew
.Fields("fldHoliday") = "Anaximander Day"
.Update
.AddNew
.Fields("fldHoliday") = "Plato Day"
.Update
.Index = "AlphaHoliday"
.MoveFirst
MsgBox .Fields("fldHoliday") 'Anixamder Day
.MoveNext
MsgBox .Fields("fldHoliday") 'Plato Day
.MoveLast
MsgBox .Fields("fldHoliday") 'Xerxes Day
.Close
End With
End With
End With
>VirtualDAORecordSetExit:
Set Rcs = Nothing
DBEngine.Rollback
Exit Function
>CreateTableErr:
With Err
If .Number = 3010 Then
Counter = Counter + 1
TableName = "tblTemp" & CStr(Counter)
Resume
Else
MsgBox .Number & " " & .Description
Resume VirtualDAORecordSetExit
End If
End With
>End Function


Lyle Fairfield's Avatar
Lyle Fairfield July 18th, 2006 04:15 AM
Guest - n/a Posts
#5: Re: DAO Connectionless Recordset?


Tom van Stiphout wrote:
Quote:
Originally Posted by
On 17 Jul 2006 09:05:10 -0700, "Lyle Fairfield"
<lylefairfield@aim.comwrote:
>
Anaximander? That's kind-a obscure. Scolars don't even agree on his
birth year, let alone birth date. And no women in the list (or did you
just provide a fragment of your code)?
Your transaction idea is just as obscure. It probably works, but would
you want it to?


So sorry ... it was a typo for Anixemenes.

I don't think I'd want to. I have used temporary tables within
transactions when dealing with some ghastly non-normalized genealogical
tables where the calculations were very intensive ... follwing back
parents; to simplify this I created the temp tables, indexed them and
scanned through them, writing and ftping up html files for each person
.... I do think this simplified things by giving me two or three
standard tables that were designed just for this modules needs. By
indexing these I could find a son/daughter/second wife/whatever pdq ...
even counting creating the tables and indexes the thing ran several
hundred times faster than using the disorganized data. Of course the
tables were never saved ...also of course, Access itself had no
knowledge of them, even during their existence.

 
Not the answer you were looking for? Post your question . . .
197,027 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,027 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors