Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO save database BASICS save Recordset basics

Status
Not open for further replies.

WARLOCK

Programmer
Aug 14, 2001
4
US
OK all lets see if it was the nature of my other thread or if its just me that cant get an answer in this forum.

This should be an easy one for anyone of you who uses ADO. I access an Access database with ADODB. I establish a connection, and specify a table name in the connection string. No ADODB specific command object is used.
I can make changes to the recordset on my form but any attempts to save ( Updatebatch ) or rs.save "path-N-filename.mdb" either leave a 1KB access database for new creations or result in the error of file already exists.

Can someone provide the BASICS for saving a recordset and dataase to avoid this error. Lets say I create a NEW recordset & somehow get my stream into it from my other thread in this forum. How do I correctly attach this NEW recordset to a database I just created in ADOX, (catalog object) and save it to disk without the error that the file exists already.
Please someone this is not for production its just to strengthen my understanding (or lack thereof) in saving recordsets.
I am trying to avoid SQL in this little test I.E. the ADODB command object also. But if it's needed please educate ME !!!
If anyone cares all this is just to continue my efforts in the stream object of ADODB & parsing via XML format.. per my previous thread "STREAMS"
But I'll take what ever I can get.

Thank You So much for your time. I do appreciate any and all responses.
Christianvbprogrammer@yahoo.com
 
Here is a code which creates disconnected recordset from the scratch








If Not myRecordset Is Nothing Then
If myRecordset.State = adStateOpen Then
myRecordset.Close
End If
End If

Set myRecordset = New ADODB.Recordset

With myRecordset.Fields

Set myRecordset.ActiveConnection = Nothing
myRecordset.CursorLocation = adUseClient

.Append "FieldName1", adInteger
.Append "FieldName2", adVarChar, 60
.
.
.
.Append "FieldNameN", adVarChar, 12

myRecordset.Open
End With

Now you can populate this recordset with new records using AddNew method of
recordset. If you want to connect this recordset to any databse check July
or August (I do not remember exactly) issue of VBPJ magazine. They describe
technique of connecting fabricated recordsets to database using XML.

If you want to create disconnected recordset based on database then do next

If Not myRecordset Is Nothing Then
If myRecordset.State = adStateOpen Then
myRecordset.Close
End If
End If

Set myRecordset = New ADODB.Recordset

Set myRecordset.ActiveConnection = myConn 'where myConn previously opened
connection to database
myRecordset.CursorLocation = adUseClient
myRecordset.Open "SELECT * FROM Table"
Set myRecordset.ActiveConnection = Nothing

Now you can work with recordset (change, add new data). If you want to
connect it to same databse, then you just need to set its connection back to
MyConn and provide batch update

Set myRecordset.ActiveConnection = myConn
myRecordset.UpdateBatch

This will save all changes to database.
If you want to connect this recordset to another database then you will need
to use same technique as for fabricated recordset before (see VBPJ)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top