Solved

Create a recordset and print in Debug.print

Posted on 2008-10-27
7
3,342 Views
Last Modified: 2013-11-25
I am trying to reach myself more about recordsets as I have an issue that needs them.  I have data that comes from an Excel spreadhseet.  This data needs to be separated by branches and then automatically e-amiled to somenoe at the branch.  Now, I am developing this in stages and the first thing I am trying to do is create a recordset.  Simple, I have the data in the table but am trying to simply create a recordset and send the data to the Immediatley window.  But I keep getting a datatype mismatch when it hit the debug.print statement.
'First check upload to be sure that it and the report type are of the same

'type.  If not, warn user and exit sub.

Dim rst As Recordset, db As DAO.Database

Set db = CurrentDb

Set rst = db.OpenRecordset("tblAMLUploadedToday", dbOpenTable)

Do Until rst.EOF

Debug.Print rst

rst.MoveNext

Loop

End Sub

Open in new window

0
Comment
Question by:ssmith94015
  • 4
  • 3
7 Comments
 
LVL 44

Expert Comment

by:GRayL
ID: 22817520
Debug.Print rst!fld1, rst!fld2, rst!fld3, etc.  

you must provide each of the field names for that recordset record.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 22817552
Another way:
'First check upload to be sure that it and the report type are of the same

'type.  If not, warn user and exit sub.

Dim rst As Recordset, db As DAO.Database, fld as field

Set db = CurrentDb

Set rst = db.OpenRecordset("tblAMLUploadedToday", dbOpenTable)

Do Until rst.EOF

  for each fld in rst.fields: Debug.Print rst(fld):next fld

  rst.MoveNext

Loop

End Sub

Open in new window

0
 
LVL 44

Accepted Solution

by:
GRayL earned 500 total points
ID: 22817565
Lets reset that:


'First check upload to be sure that it and the report type are of the same

'type.  If not, warn user and exit sub.

Dim rst As Recordset, db As DAO.Database, fld as field

Set db = CurrentDb

Set rst = db.OpenRecordset("tblAMLUploadedToday", dbOpenTable)

Do Until rst.EOF

  for each fld in rst.fields: Debug.Print rst(fld),:next fld

  rst.MoveNext

Loop

End Sub

Open in new window

0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:ssmith94015
ID: 22817665
This is an ACCESS database and I am getting an ITEM NOT FOUND IN TIHS COLLECTION error when it hits : Debug.Print rst(fld),
0
 

Author Comment

by:ssmith94015
ID: 22817701
Got it to work with a slight modiification.  Also, if I want to have the data across the page, then I woudl have to list out the fileds individually?  Somethign like

rst.field(1), rst.field(2). rst.field(3)........ after the debug.print.
Dim rst As Recordset, db As DAO.Database, fld As Field

Set db = CurrentDb

Set rst = db.OpenRecordset("tblAMLUploadedToday", dbOpenTable)

Do Until rst.EOF

        For Each fld In rst.Fields

          Debug.Print fld

        Next fld

  rst.MoveNext

Loop
 

End Sub

Open in new window

0
 

Author Closing Comment

by:ssmith94015
ID: 31510553
Thank you.  This is just start of trying to figure out a rather complex process but I needed to learn how to do this.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 22826352
Did you notice the comma at the end of my debug.print statement?  that is the equivalent of a tab, and should keep all the fields in the same line.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now