473,397 Members | 2,068 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,397 software developers and data experts.

Is there a way to open a *FILTERED* recordset on an excel file ?

Hi,

I have the following problem: I open a recordset based on excel/csv
files, but then I need to filter (in code) in order to extract only
data pertaining to a specific person. This code is slow....

I am thinking that there might be another way to do it... maybe faster.
Is there a way to filter it as I open it ?

I'm using the following simple code:

Private Function Util_ReadTextFile(strDir As String, strFileName As
String) As DAO.Recordset

On Error GoTo Util_ReadTextFile_Error

Dim db As DAO.Database
Dim rstOpened As DAO.Recordset

Set db = DBEngine.Workspaces(0).OpenDatabase(strDir, False, False,
"Text;")
Set rstOpened = db.OpenRecordset(strFileName, dbOpenDynaset,
dbReadOnly)
Set Util_ReadTextFile = rstOpened

Util_ReadTextFile_Exit:
Exit Function

Util_ReadTextFile_Error:
MsgBox Err & ", " & Error, vbInformation
Resume Util_ReadTextFile_Exit
End Function

..... and then I use smth like

Set rstData = Util_ReadTextFile(....)
rstData.Filter = "PIN = ...."
Set rstDataFiltered = rstData.OpenRecordset

If there is a way, would it be any faster ?

Thank you !
Alex

May 7 '06 #1
8 2335
On 6 May 2006 18:34:39 -0700, "Radu" <cu*************@yahoo.com>
wrote:

Not sure why you're opening Excel files as Text. I'm sure they're not
Excel files. Just try opening them in Notepad.

Sometimes it is faster to import the text file into an Access table,
set an index, and use that index to find or filter records.

-Tom.

Hi,

I have the following problem: I open a recordset based on excel/csv
files, but then I need to filter (in code) in order to extract only
data pertaining to a specific person. This code is slow....

I am thinking that there might be another way to do it... maybe faster.
Is there a way to filter it as I open it ?

I'm using the following simple code:

Private Function Util_ReadTextFile(strDir As String, strFileName As
String) As DAO.Recordset

On Error GoTo Util_ReadTextFile_Error

Dim db As DAO.Database
Dim rstOpened As DAO.Recordset

Set db = DBEngine.Workspaces(0).OpenDatabase(strDir, False, False,
"Text;")
Set rstOpened = db.OpenRecordset(strFileName, dbOpenDynaset,
dbReadOnly)
Set Util_ReadTextFile = rstOpened

Util_ReadTextFile_Exit:
Exit Function

Util_ReadTextFile_Error:
MsgBox Err & ", " & Error, vbInformation
Resume Util_ReadTextFile_Exit
End Function

.... and then I use smth like

Set rstData = Util_ReadTextFile(....)
rstData.Filter = "PIN = ...."
Set rstDataFiltered = rstData.OpenRecordset

If there is a way, would it be any faster ?

Thank you !
Alex


May 7 '06 #2
rkc
Radu wrote:
Hi,

I have the following problem: I open a recordset based on excel/csv
files, but then I need to filter (in code) in order to extract only
data pertaining to a specific person. This code is slow....

I am thinking that there might be another way to do it... maybe faster.
Is there a way to filter it as I open it ?

I'm using the following simple code:

Private Function Util_ReadTextFile(strDir As String, strFileName As
String) As DAO.Recordset

On Error GoTo Util_ReadTextFile_Error

Dim db As DAO.Database
Dim rstOpened As DAO.Recordset

Set db = DBEngine.Workspaces(0).OpenDatabase(strDir, False, False,
"Text;")
Set rstOpened = db.OpenRecordset(strFileName, dbOpenDynaset,
dbReadOnly)
Set Util_ReadTextFile = rstOpened

Util_ReadTextFile_Exit:
Exit Function

Util_ReadTextFile_Error:
MsgBox Err & ", " & Error, vbInformation
Resume Util_ReadTextFile_Exit
End Function

.... and then I use smth like

Set rstData = Util_ReadTextFile(....)
rstData.Filter = "PIN = ...."
Set rstDataFiltered = rstData.OpenRecordset

If there is a way, would it be any faster ?


Use a SELECT statement with a WHERE clause when opening the recordset.

sSelect = "SELECT * FROM " & strFileName _
& " WHERE PIN = 007"

Set rstOpened = db.OpenRecordset(sSelect, dbOpenDynaset, bReadOnly)

May 7 '06 #3
Hi. Thanks for answering

1. Tom, No, they are txt, or csv, or xls files - reading them has to be
done programatically, Notepad won't help :-))
2. RKC, I'll try that right now - I'll time it to see if there is any
improvement.

May 7 '06 #4
DAO.Recordsets are time-consuming and awkward. Witness here, where you
created 3 Recordset pointers, 2 of them to the same data and one to a
subset of it.

Possibly a much faster way is not to open a Recordset.

Of course, there may be some special reason that you need a Recordset.
Could you tell us what you do with the data after "Set
rstDataFiltered = rstData.OpenRecordset"? Perhaps there is an efficient
way to move the data from the text file to wherever you need it without
using the Recordset.

May 7 '06 #5
"Radu" <cu*************@yahoo.com> wrote in
news:11**********************@i39g2000cwa.googlegr oups.com:
Hi. Thanks for answering

1. Tom, No, they are txt, or csv, or xls files - reading them
has to be done programatically, Notepad won't help :-))
..txt and .csv files open perfectly in notepad. .xls is different,
but your code won't open those correctly.
2. RKC, I'll try that right now - I'll time it to see if there
is any improvement.

RKC's method would be faster.
--
Bob Quintal

PA is y I've altered my email address.
May 7 '06 #6
"Radu" <cu*************@yahoo.com> wrote in
news:11**********************@e56g2000cwe.googlegr oups.com:
If there is a way, would it be any faster ?


Why not just create a table link with TransferText and then you
wouldn't have to care that it's an external file, as it would work
just like any table.

However, note that if there are many rows, filtering could be quite
slow, as a full table scan will be required, since there are no
indexes. If it's a lot of data and filtering is slow, I'd just
import the darned thing and create an index on the filtered field.
The time it takes to do that will probably be much less than the
time it takes to filter the unindexed recordset.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
May 7 '06 #7
Hi.
I have tried with filtering - and it's even slower ! :-(

Why do I need to filter ? Well, let me explain: the data in each file
contains a lot of info pertaining to a list of PINs - say I have to
gather info for 1000 PINS, contained in an "Master" Excel file, let's
call it Z, and in input file "A" I *might* have info for PINS 2, 4, 77,
82..., for a total of 224 PINS. In other input file, say "B", I might
have data for PINS 22, 34, 36, etc, for a total of 162 PINS, and so on.

I need to access info for each PIN in my master list (Z) of 1000 PINs,
to process that data according to the business rules, and to push it in
some word docs.

So, besides Z, I also have a table T containing the list of input files
(A, B, C, etc). These files (A, B, C...) might be CSV, txt, XLS, etc. I
loop thru all 1000 PINs in Z, and for each one I open in turn each of
those files from T, filter them for the current PIN and I extract the
data for that PIN, if found.

I cannot import/link those files manually, because the list of input
files must by dynamic for each run (as it is (configurable by the user)
in the table T containing the list of input files).

The other idea is this - I will try to link A, B, C.... by code (by
browsing in T) and then do some left joins (on the left being the
master PIN file, Z) so that in the end I obtain some kind of flat file,
ready to be used as datasource for the word documents.

I still have other issues here pertaining to the flexibility - nothing,
but nothing, can be hardcoded - all files, including T and Z, must be
specified by the user, and they don't even have set field names - the
only constraint I will be able to set is that the first column in all
tables has to be the PIN column, although the name of that column has
to be variable as well). I might (I don't know yet, but knowing the
user I have to be prepared for anything) to also provide for calculated
fields, whose formulas shouls also be configurable at run-time....

Anyway, I wonder if, in the end, I will obtain a significant speed
improvement by using this method and avoiding looping, as I currently
do.

For now, what I have done, though, is that on startup I run a "Select
distinct" on my table T and then I read all input files and put them in
a pool, so as to avoid opening them repeatedly. This helped. Other than
that....

Thanks all for the kindness of answering.
Alex.

May 8 '06 #8
"Radu" <cu*************@yahoo.com> wrote in
news:11**********************@i40g2000cwc.googlegr oups.com:
I have tried with filtering - and it's even slower ! :-(
Then import into a table and add an index on the fields you're
selecting on.
Why do I need to filter ? Well, let me explain: the data in each
file contains a lot of info pertaining to a list of PINs - say I
have to gather info for 1000 PINS, contained in an "Master" Excel
file, let's call it Z, and in input file "A" I *might* have info
for PINS 2, 4, 77, 82..., for a total of 224 PINS. In other input
file, say "B", I might have data for PINS 22, 34, 36, etc, for a
total of 162 PINS, and so on.

I need to access info for each PIN in my master list (Z) of 1000
PINs, to process that data according to the business rules, and to
push it in some word docs.

So, besides Z, I also have a table T containing the list of input
files (A, B, C, etc). These files (A, B, C...) might be CSV, txt,
XLS, etc. I loop thru all 1000 PINs in Z, and for each one I open
in turn each of those files from T, filter them for the current
PIN and I extract the data for that PIN, if found.
Are these external files static? Even if they aren't, it would still
be faster to clear the last import from an existing table and import
the current version than it would be to filter on a direct link.
I cannot import/link those files manually, . . .
I wasn't suggesting a manual import.
. . . because the list of input
files must by dynamic for each run (as it is (configurable by the
user) in the table T containing the list of input files).
Well, surely the structure of the files is fixed, no? If so, then
you can program it, and allow the user to choose the file with a
file open dialog.
The other idea is this - I will try to link A, B, C.... by code
(by browsing in T) and then do some left joins (on the left being
the master PIN file, Z) so that in the end I obtain some kind of
flat file, ready to be used as datasource for the word documents.
With external files, that will be as slow as your filtering, since
there is no indexing.

It sounds to me like importing into tables with indexed fields is
the way to go.
I still have other issues here pertaining to the flexibility -
nothing, but nothing, can be hardcoded - all files, including T
and Z, must be specified by the user, and they don't even have set
field names - the only constraint I will be able to set is that
the first column in all tables has to be the PIN column, although
the name of that column has to be variable as well). I might (I
don't know yet, but knowing the user I have to be prepared for
anything) to also provide for calculated fields, whose formulas
shouls also be configurable at run-time....
You're saying that the files *don't* have a fixed structure?

Well, then, you're stuck with slow performance.

Sounds like the system you're working with was designed by an idiot.
Anyway, I wonder if, in the end, I will obtain a significant speed
improvement by using this method and avoiding looping, as I
currently do.
You won't gain any speed by linking. The cause of the performance
slowdown is always the same -- you'd be joining or filtering on data
sources that have no indexes.
For now, what I have done, though, is that on startup I run a
"Select distinct" on my table T and then I read all input files
and put them in a pool, so as to avoid opening them repeatedly.
This helped. Other than that....


Why in the world is your Access app dependent on text data? Is there
no direct route for getting the information?

Of course, I'm assuming from what you've said that the external file
layouts are variable. If they aren't, then importing is the way to
go.

If they aren't, I'd look into trying to get someone to re-engineer
the external dependencies, since they seem to have not been designed
to make it possible to do what you need efficiently.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
May 8 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
1
by: mike newman | last post by:
I am trying to output a recordset that I have to Excel XP? I don't know how to do it. I have the Office 10 COM Object library reference, and I just need to know how to take my recordset, locate...
1
by: Lize | last post by:
Hi, I'm writing an ASP application to open an excel workbook, then run a macro stored in the excel file, which produces outputs that will be displayed back onto my ASP application. Now the...
6
by: John | last post by:
Just a general question... I'm currently using a combobox that when updated, opens a form with its recordset based on a query using the combo box value as the criteria. I'm I correct in...
1
by: Jim | last post by:
This should really be simple, but I can't figure it out. I have some VB that exports a table in an Excel format ("C:\NewReport.xls"). After the export is done, I simply want to have some code...
1
by: Jaime Leivers | last post by:
Here's a median function in access that you can call in any query. You could change this to any excel function you wanted. Most people can find the windows help file that says how to call an excel...
3
by: melnhed | last post by:
---Report the current filtered records from a Form--- Hello All, I've seen this topic discussed before, but the solution described then doesn't work in my particular case. My Config: ...
2
by: atlbearcat | last post by:
Here's one that's been bugging me for about a week now... I have a form that allows users to filter records, simple enough. But I want to give them the option to export the filtered records to...
1
by: sunnyluthra1 | last post by:
Hi Everyone, I am working on a piece of code, that displays the properties(Name, Datatype, size & Description) of the table in the database. Now I want to further Enhance the code. I Have created...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.