473,748 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help creating a disconnected recordset in VBA

39 New Member
Here is the code that I copied and pasted from the internet, and I have been trying to modify it to fit what I am doing. The code is getting stuck on what seems to be pretty simple things (on the "Set conn = New DAO.Connection" ) with a message coming up saying "Complie error: User-defined type not defined". I'm sure there are going to be quite a few more compile errors after I get this one worked out as well.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. 'Sub Rst_Disconnected()
  3.     Dim conn As DAO.Connection
  4.     Dim myRecordset As DAO.Recordset
  5.     Dim strConn As String
  6.     Dim strSQL As String
  7.     Dim strRst As String
  8.  
  9.     strSQL = "SELECT * FROM Clients"
  10.  
  11.     strConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
  12.     strConn = strConn & "Data Source = " & "(database file-path)" & "\mydb.mdb"
  13.  
  14.     Set conn = New DAO.Connection
  15.     conn.ConnectionString = strConn
  16.     conn.Open
  17.  
  18.     Set myRecordset = New DAO.Recordset
  19.     Set myRecordset.ActiveConnection = conn
  20.     ' retrieve the data
  21.     myRecordset.CursorLocation = callForm
  22.     myRecordset.LockType = adLockBatchOptimistic
  23.     myRecordset.CursorType = adOpenStatic
  24.     myRecordset.Open strSQL, , , , adCmdText
  25.  
  26.     Set myRecordset = db.OpenRecordset("Clients", dbOpenDynaset)
  27.  
  28.     Set myRecordset.ActiveConnection = Nothing
  29.  
  30.     If Rs.RecordCount <> 0 Then
  31.         myRecordset.MoveFirst
  32.         Debug.Print myRecordset.Fields(0) & " was " & myRecordset.Fields(1) & " before."
  33.         'myRecordset.Fields("CustomerID").Value = "OCEAN"
  34.         myRecordset.Update
  35.     End If
  36.  
  37.     strRst = myRecordset.GetString(adClipString, , ",")
  38.     Debug.Print strRst
  39. End Sub
  40.  
I hope this is enough for you all to work off of to help me, if you need anymore information, please let me know.
Feb 18 '11 #1
1 6773
ADezii
8,834 Recognized Expert Expert
DAO does not support Disconnect Recordsets, you must use ADO. I've posted the General Idea below:
Expand|Select|Wrap|Line Numbers
  1. Dim conn As ADODB.Connection
  2. Dim myRecordset As ADODB.Recordset
  3. Dim strConn As String
  4. Dim strSQL As String
  5. Dim strRst As String
  6.  
  7. strSQL = "SELECT * FROM Clients"
  8.  
  9. strConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
  10. strConn = strConn & "Data Source = " & "(database file-path)" & "\mydb.mdb"
  11.  
  12. Set conn = New ADODB.Connection
  13. conn.ConnectionString = strConn
  14.   conn.Open
  15.  
  16. Set myRecordset = New ADODB.Recordset
  17.  
  18. With myRecordset
  19.   .ActiveConnection = conn
  20.   .CursorLocation = adUseClient
  21.   .LockType = adLockBatchOptimistic
  22.   .CursorType = adOpenStatic
  23.     .Open strSQL, , , , adCmdText
  24. End With
  25.  
  26. 'Disconnect
  27. Set conn = Nothing
  28.  
  29. 'Modify Data, Recordset is disconnected but fully functional
  30.  
  31. 'Reconnect using the Connection Object
  32.  
  33. 'Update Source
  34. rstDisconnect.UpdateBatch
  35.  
  36. 'Check any changes made while disconnected
Feb 19 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3243
by: Andie | last post by:
Hello All, How would I go about using a disconnect recordset and select (x) records from it, x being the number of records to be selected. Many thanks in advance. -- Andie
4
5059
by: Thomas Scheiderich | last post by:
Why would you use the Recordset object over the Execute method of getting data from your Sql database. For example, I have the following: Execute Method *************************************************************** Set connectionToDatabase=Server.CreateObject("ADODB.Connection") connectionToDatabase.ConnectionTimeout = 60 connectionToDatabase.Open "DSN=Customer;user id=SA;password="
4
4748
by: Agoston Bejo | last post by:
I would like to use an ADODB.RecordSet object to temporarily store some data and then iterate through it. Actually it needs to be a RecordSet only because it is a perfect choice as data structure for what I want to do, I don't want to actually run queries or update tables with it. It seems to me, however, that the RecordSet works only if there's a query behind it. ADO complains about the RecordSet not being open when I try to add rows by...
1
1856
by: Mark | last post by:
Hi - I have a recordset generated from a search between two dates - if the user wishes to 'update' some of the records to show their interest in some of the dates, is there a way I can just update the recordset, and write it back to the database (used to use rs.Edit, rs.Update etc in old ASP) - or do I still need to run an update query for the records I want to update? Thanks for any pointers, *** Sent via Developersdex...
6
2946
by: Steve Jorgensen | last post by:
I keep having problems in which ADO disconnected recordset work under some circumstances, but lose all their data at other times, having no rows or fields, though the recordset object still exists. One case where this happened to me today was in trying to store disconnected recordsets in a cache collection in case they are needed again later in the same session. When I retrieve the recordset from the collection, it's empty. On the other...
3
2224
by: Liz Malcolm | last post by:
Hello and TIA for guidance. I am building a reusable search procedure (thanks go to Graham Thorpe for his example that set me on my way). Everything works up until the 2nd match is found, the command doesn't go to the third match, it exits out of the loop. I've read everything I could find in NG's, but I can't figure out where I'm going wrong. Here is my code. Function cmdSearch(ctlSearchText As Control, ctlFoundText As Control,...
2
2878
by: Eric Peterson | last post by:
I use the shape object to make recordsets that have no db connection for use in grids and such. For example (mPhoneNumbersRS as ADODB.Recordset) **************************************** mPhoneNumbersRS.let_ActiveConnection ("Provider=MSDataShape;Data Provider=none;Data Source=localhost;") sTmp = "SHAPE APPEND NEW adChar(20) as Type, NEW advarChar
4
5493
by: andy.mcvicker | last post by:
Hi Gang I have a large VB program that at one point does a lookup to a small table (26 rows by 3 columns). With this table I have to do some counting and retrieval of data. I'm finding that this slows the program right down. Is there any way I can take a copy of the table in memory and access it there. Perhaps a cursor or something? Can someone help with a code sample. Here's my code to do the lookup.
1
2249
by: Arpan | last post by:
Recently in an interview (for the post of ASP programmer), I was asked "How do you define disconnected recordset in ASP". I was stumped & couldn't answer. What's the answer to the question? Is it GetRows()? Thanks, Regards, AD
0
8991
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
9552
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
9326
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
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
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
4877
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
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
3
2215
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.