Sandra Smith
asked on
Create a recordset and print in Debug.print
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is an ACCESS database and I am getting an ITEM NOT FOUND IN TIHS COLLECTION error when it hits : Debug.Print rst(fld),
ASKER
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.
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
ASKER
Thank you. This is just start of trying to figure out a rather complex process but I needed to learn how to do this.
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.
you must provide each of the field names for that recordset record.