Hello guys,
I am running the script below and am able to load my recordset and cycle through the values in the fields. However I want to use the .AbsolutePosition property to help place the data into specific cells in Excel. The problem is no matter what I seem to do the AbsolutePosition property alwas returns a value of -1. I know that would normally mean there are no records in my recordset but the fld.Value does show the correct data from my SQL query. I am using an ADODB Recordset. - With DataIO.rs
-
.MoveFirst
-
-
Do While Not .EOF
-
For Each fld In .Fields
-
Debug.Print fld.Value
-
Debug.Print .AbsolutePosition
-
Next
-
.MoveNext
-
-
Loop
-
End With
Please Help....
6 7612
Hello guys,
I am running the script below and am able to load my recordset and cycle through the values in the fields. However I want to use the .AbsolutePosition property to help place the data into specific cells in Excel. The problem is no matter what I seem to do the AbsolutePosition property alwas returns a value of -1. I know that would normally mean there are no records in my recordset but the fld.Value does show the correct data from my SQL query. I am using an ADODB Recordset. - With DataIO.rs
-
.MoveFirst
-
-
Do While Not .EOF
-
For Each fld In .Fields
-
Debug.Print fld.Value
-
Debug.Print .AbsolutePosition
-
Next
-
.MoveNext
-
-
Loop
-
End With
Please Help....
- It is very posible that the Recordset does not support the AbsolutePosition Property, but this can be found out ahead of time:
The Supports Method of an ADODB Recordset - If you are simply traversing the Recordset, you can create a 'pseudo' AbsolutePosition Property:
-
Dim intAbsolutePosition As String
-
-
intAbsolutePosition = 0
-
-
With DataIO.rs
-
.MoveFirst
-
intAbsolutePosition = intAbsolutePosition + 1
-
Do While Not .EOF
-
For Each fld In .Fields
-
Debug.Print fld.Value
-
Debug.Print intAbsolutePosition
-
Next
-
.MoveNext
-
Loop
-
End With
Thanks for the insight on that, it never occured to me that all of the available object properties for a recordset would not be accessible. Other than arbitrarily needing to check every recordset for compatiblity is there something in the data set that determines this? Such as how the table is set up in Access or the like? That would maybe help to determine if there is some way to change the table so that a recordset query could use the properties.
Thanks for the insight on that, it never occured to me that all of the available object properties for a recordset would not be accessible. Other than arbitrarily needing to check every recordset for compatiblity is there something in the data set that determines this? Such as how the table is set up in Access or the like? That would maybe help to determine if there is some way to change the table so that a recordset query could use the properties.
I'm not exactly sure what the Parameters are, but I am under the impression that they are confusing and relatively complex. Why not simply check for this up front, then adjust the code accordingly? -
Dim intAbsolutePosition As String
-
-
intAbsolutePosition = 0
-
-
If DataIO.rs.Supports(adApproxPosition) Then 'supports AbsolutePosition
-
With DataIO.rs
-
.MoveFirst
-
Do While Not .EOF
-
For Each fld In .Fields
-
Debug.Print fld.Value
-
Debug.Print .AbsolutePosition
-
Next
-
.MoveNext
-
Loop
-
End With
-
Else 'does not support AbsolutePosition
-
With DataIO.rs
-
.MoveFirst
-
intAbsolutePosition = intAbsolutePosition + 1
-
Do While Not .EOF
-
For Each fld In .Fields
-
Debug.Print fld.Value
-
Debug.Print intAbsolutePosition
-
Next
-
.MoveNext
-
Loop
-
End With
-
End If
I have a similar issue. I'm trying to determine the number of rows returned by the query before I shove the data into excel. I had originally written the code below, only to find that my recordset does not support it (rs.Supports(adApproxPosition) = FALSE). The goal is to notify the user when they run a query that returns more data than Excel 2003 can handle (65,536) and exit the program. I could run this on the SQL side, using TOP, but that would involve running the query twice and would hurt performance (take 2x as long). Any ideas are appreciated. -
-
rs.Open cmdText, cnn1
-
-
'Copy the table data into the spreadsheet
-
If rs.RecordCount > 65500 Then 'Check for more rows than Excel 2003 can handle (65,535)
-
rs.Close
-
cnn1.Close
-
MsgBox "The Query is returning too much data. Please reduce your date range and try again.", vbOKOnly
-
Exit Sub
-
Else 'Copy the table data into the spreadsheet
-
Sheets("Data").Select
-
Range("B2").CopyFromRecordset rs
-
End If
-
-
rs.Close
-
cnn1.Close
-
-
I have a similar issue. I'm trying to determine the number of rows returned by the query before I shove the data into excel. I had originally written the code below, only to find that my recordset does not support it (rs.Supports(adApproxPosition) = FALSE). The goal is to notify the user when they run a query that returns more data than Excel 2003 can handle (65,536) and exit the program. I could run this on the SQL side, using TOP, but that would involve running the query twice and would hurt performance (take 2x as long). Any ideas are appreciated. -
-
rs.Open cmdText, cnn1
-
-
'Copy the table data into the spreadsheet
-
If rs.RecordCount > 65500 Then 'Check for more rows than Excel 2003 can handle (65,535)
-
rs.Close
-
cnn1.Close
-
MsgBox "The Query is returning too much data. Please reduce your date range and try again.", vbOKOnly
-
Exit Sub
-
Else 'Copy the table data into the spreadsheet
-
Sheets("Data").Select
-
Range("B2").CopyFromRecordset rs
-
End If
-
-
rs.Close
-
cnn1.Close
-
-
I'm sorry but I'm a little confused, what is rs.RecordCount returning?
Hi ADezii. The Recordcount property of a DAO recordset returns the total number of records in the recordset (at least it does if a MoveLast is done before referring to it, otherwise the count can be inaccurate).
-Stewart
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Hung Huynh |
last post by:
Hi,
I'm trying to use either one of these methods to position the cursor in a
specific position inside a recordset, but neither one seems to work.
For example, I have 10 records in my rsData...
|
by: J.D. Buehls |
last post by:
I have a bit of code that goes through a recordset and renumbers the
records from 1 to X. I could swear that this code worked before but
now when it is run,
all of the records end up being...
|
by: !TG |
last post by:
I currently use Do while loop, but I'd rather use a For Loop though I
have never gotten the hang of them.
Would some one please be so kind as to show me how to loop through a
recordset.
|
by: Ray Holtz |
last post by:
I have a database in Access 2003 (Access2000 file format). There are
two tables that are being used: Employees and Items. It is linked by
the Employee field so that one employee can have many...
|
by: Tom van Stiphout |
last post by:
Hi all,
I'm seeing a weird problem I'm thinking might be due to corruption.
What do you think?
Here is the relevant code, which is in a standard module, called from
subfrmDetail's...
|
by: mssbass |
last post by:
In order to disable the previous and next buttons on my form, I followed the attached code. The buttons seem to work fine except for one thing. When the form first opens, the next button is...
|
by: beebelbrox |
last post by:
Hi, I am new VB programming in Access and I am requesting help with the following code.
This code is attached to a form that will display a specific recordset based in information passed to the...
|
by: bluepiper |
last post by:
Im using VB6. On rowcolchange event of may datagrid, im using the Frame caption to get the selected data. The problem is when I select the data on the grid. Its not showing the absolute position,...
|
by: ADezii |
last post by:
When you create an ADO Recordset, you should have some idea as to what functionality the Recordset does/does not provide. Some critical questions may, and should, be:
Can I add New Records to the...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |