473,383 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Recordset.AbsolutePosition returns value of -1

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.

Expand|Select|Wrap|Line Numbers
  1. With DataIO.rs
  2.     .MoveFirst
  3.  
  4.     Do While Not .EOF
  5.         For Each fld In .Fields
  6.             Debug.Print fld.Value
  7.             Debug.Print .AbsolutePosition
  8.         Next
  9.         .MoveNext
  10.  
  11.     Loop
  12. End With
Please Help....
Jan 16 '08 #1
6 7612
ADezii
8,834 Expert 8TB
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.

Expand|Select|Wrap|Line Numbers
  1. With DataIO.rs
  2.     .MoveFirst
  3.  
  4.     Do While Not .EOF
  5.         For Each fld In .Fields
  6.             Debug.Print fld.Value
  7.             Debug.Print .AbsolutePosition
  8.         Next
  9.         .MoveNext
  10.  
  11.     Loop
  12. End With
Please Help....
  1. 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
  2. If you are simply traversing the Recordset, you can create a 'pseudo' AbsolutePosition Property:
    Expand|Select|Wrap|Line Numbers
    1. Dim intAbsolutePosition As String
    2.  
    3. intAbsolutePosition = 0
    4.  
    5. With DataIO.rs
    6.   .MoveFirst
    7.    intAbsolutePosition = intAbsolutePosition + 1
    8.     Do While Not .EOF
    9.       For Each fld In .Fields
    10.         Debug.Print fld.Value
    11.         Debug.Print intAbsolutePosition
    12.       Next
    13.         .MoveNext
    14.     Loop
    15. End With
Jan 17 '08 #2
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.
Jan 17 '08 #3
ADezii
8,834 Expert 8TB
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?
Expand|Select|Wrap|Line Numbers
  1. Dim intAbsolutePosition As String
  2.  
  3. intAbsolutePosition = 0
  4.  
  5. If DataIO.rs.Supports(adApproxPosition) Then      'supports AbsolutePosition
  6.   With DataIO.rs
  7.     .MoveFirst
  8.       Do While Not .EOF
  9.         For Each fld In .Fields
  10.           Debug.Print fld.Value
  11.           Debug.Print .AbsolutePosition
  12.         Next
  13.           .MoveNext
  14.       Loop
  15.   End With
  16. Else      'does not support AbsolutePosition
  17.   With DataIO.rs
  18.     .MoveFirst
  19.      intAbsolutePosition = intAbsolutePosition + 1
  20.       Do While Not .EOF
  21.         For Each fld In .Fields
  22.           Debug.Print fld.Value
  23.           Debug.Print intAbsolutePosition
  24.         Next
  25.           .MoveNext
  26.       Loop
  27.   End With
  28. End If
Jan 17 '08 #4
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. rs.Open cmdText, cnn1
  3.  
  4. 'Copy the table data into the spreadsheet
  5. If rs.RecordCount > 65500 Then  'Check for more rows than Excel 2003 can handle (65,535)
  6.     rs.Close
  7.     cnn1.Close
  8.     MsgBox "The Query is returning too much data.  Please reduce your date range and try again.", vbOKOnly
  9.     Exit Sub
  10. Else    'Copy the table data into the spreadsheet
  11.     Sheets("Data").Select
  12.     Range("B2").CopyFromRecordset rs
  13. End If
  14.  
  15. rs.Close
  16. cnn1.Close
  17.  
  18.  
Mar 18 '08 #5
ADezii
8,834 Expert 8TB
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. rs.Open cmdText, cnn1
  3.  
  4. 'Copy the table data into the spreadsheet
  5. If rs.RecordCount > 65500 Then  'Check for more rows than Excel 2003 can handle (65,535)
  6.     rs.Close
  7.     cnn1.Close
  8.     MsgBox "The Query is returning too much data.  Please reduce your date range and try again.", vbOKOnly
  9.     Exit Sub
  10. Else    'Copy the table data into the spreadsheet
  11.     Sheets("Data").Select
  12.     Range("B2").CopyFromRecordset rs
  13. End If
  14.  
  15. rs.Close
  16. cnn1.Close
  17.  
  18.  
I'm sorry but I'm a little confused, what is rs.RecordCount returning?
Mar 18 '08 #6
Stewart Ross
2,545 Expert Mod 2GB
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
Mar 18 '08 #7

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

Similar topics

8
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...
3
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...
5
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.
1
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...
5
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...
1
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...
0
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...
1
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,...
0
ADezii
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...
0
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...
0
isladogs
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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
0
BarryA
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...
0
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...

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.