473,769 Members | 3,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieving Data From a DAO Recordset

8 New Member
Hi everyone,

I have a question. I am creating a dynamic report from a table and need to fetch all the data (values and column names) into an array so that I can manipulate the data. I know there is a way to get the values in the recordset using GetRows() but that Only gives me the values, I also need the Field names of the columns. Does anybody know how to do this?

Thanks,
Apr 30 '10 #1
3 3950
robjens
37 New Member
Check out this you will find all you need there and more
http://allenbrowne.com/func-DAO.html
May 1 '10 #2
ADezii
8,834 Recognized Expert Expert
I wrote a basic Code Template for you. Simply pass to this Function the name of a Table, Query, or SQL Statement, and it will load the Field Names and Data into a 2-Dimensional Array. I basically threw this together, so it definately can be improved upon.
Expand|Select|Wrap|Line Numbers
  1. Public Function fProcessData(strDataSource As String)
  2. Dim MyDB As DAO.Database
  3. Dim rst As DAO.Recordset
  4. Dim bytNumOfFields As Byte
  5. Dim lngNumOfRecs As Long
  6. Dim lngRowNum As Long
  7. Dim bytFldCtr As Byte
  8.  
  9. Set MyDB = CurrentDb()
  10. Set rst = MyDB.OpenRecordset(strDataSource, dbOpenSnapshot)
  11.  
  12. 'Retrieve the Number of Fields in the Recordset
  13. bytNumOfFields = rst.Fields.Count
  14.  
  15. 'Retrieve the Number of Records in the Recordset
  16. rst.MoveLast: rst.MoveFirst
  17. lngNumOfRecs = rst.RecordCount
  18.  
  19. 'Create a 2-Dimensional Array representing Rows and Columns in a Matrix
  20. ReDim astrRecordset(0 To lngNumOfRecs, 0 To bytNumOfFields - 1)
  21.  
  22. '1st Row (0) contains Field Names, all other Rows Data
  23. For bytFldCtr = 0 To bytNumOfFields - 1
  24.   astrRecordset(0, bytFldCtr) = rst.Fields(bytFldCtr).Name
  25. Next
  26.  
  27. 'Populate Data only
  28. For lngRowNum = 1 To lngNumOfRecs               'Rows containing Data
  29.   For bytFldCtr = 0 To bytNumOfFields - 1       'Field values for each Row
  30.     astrRecordset(lngRowNum, bytFldCtr) = rst.Fields(bytFldCtr)
  31.   Next
  32.     rst.MoveNext
  33. Next
  34.  
  35. rst.Close
  36. Set rst = Nothing
  37.  
  38. 'Playback Demo
  39. 'For lngRowNum = 0 To lngNumOfRecs
  40.   'For bytFldCtr = 0 To bytNumOfFields - 1
  41.     'Debug.Print astrRecordset(lngRowNum, bytFldCtr),
  42.   'Next
  43.     'Debug.Print vbCrLf
  44. 'Next
  45. End Function
May 1 '10 #3
Executable
8 New Member
@ADezii
Thanks to all.
May 6 '10 #4

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

Similar topics

5
2235
by: aniket_sp | last post by:
i am using a data adapter and a dataset for filling and retrieving data into .mdb database. following is the code..... for the form load event Dim dc(0) As DataColumn Try If OleDbConnection1.State = ConnectionState.Closed Then OleDbConnection1.Open() Else
3
3654
by: Jakob Petersen | last post by:
Hi, I need to increase the speed when retrieving data from a hosted SQL Server into VBA. I'm using simple SELECT statements. How important is the speed of my Internet connection? (I have 4mbits) Should I index my tables or use Stored Procedures? Or is there a kind of "flush" function or readonly function or... Or is it simply a question of the amount of data transmitted over the Internet?
0
1530
by: DC01 | last post by:
I have added a new measure successfully into the normal cube. I then add it to the virtual cube and reprocess all cubes. I can browse the normal cube successfully. Then when I try and browse the virtual cube it says 'Retrieving Data' but then thats it, it just hangs like that. I am using AS2000. The other problem I have is that the data is doubling up when its in the cube. The SQL which sets up the fact tables are all fine and are...
1
1621
by: hanusoft | last post by:
This is an example of Inserting and Retrieving data from xml file. private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if(!IsPostBack) { BindGrid();
1
1672
by: hanusoft | last post by:
This is an example of Inserting and Retrieving data from xml file. private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if(!IsPostBack) { BindGrid();
4
18819
by: smartin | last post by:
Hi, I'm having problem retrieving data from an SQL stored procedure. I tried debugging but it wont give a the reason for the error. it just throws an exception after executing cmd.ExecuteNonQuery without any details. Can anyone please help me.. Im stuck on it since 2 days Thanks Stored Procedure
9
35545
ADezii
by: ADezii | last post by:
One question which pops up frequently here at TheScripts is: 'How do I retrieve data from a Recordset once I've created it?' One very efficient, and not that often used approach, is the GetRows() Method of the Recordset Object. This Method varies slightly from DAO to ADO, so for purposes of this discussion, we'll be talking about DAO Recordsets. The ADO approach will be addressed in the following Tip. We'll be using a Query, consisting of 5...
3
43528
ADezii
by: ADezii | last post by:
Last Tip, we demonstrated the technique for retrieving data from a DAO Recordset, and placing it into a 2-dimensional Array using the GetRows() Method. This week, we will cover the same exact Method (GetRows()), but only as it applies to an ADO Recordset. Although there are similarities in the 2 methodologies, the ADO Method offers 2 more Optional Arguments, is a little more complex, and of course, the syntax is different in creating the...
10
34965
vikas1111
by: vikas1111 | last post by:
Hi All Can anyone give me an idea to solve the problem.. My Problem is ,, I want to Retrieving data from database and displaying in textbox... If anybody have link of some good tutorial on this pls let me know..Or if anybody can explain I would be very thankful...
7
2737
by: splendid9 | last post by:
Problem in retrieving data from a XML file.......this is my code- protected void Page_Load(object sender, EventArgs e) { DataSet ds = new DataSet(); ds.ReadXml(MapPath("prod.xml")); DataGrid grid1 = new DataGrid(); grid1.DataSource = ds; grid1.DataBind();
0
9589
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
10211
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...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
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...
0
6673
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
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.