473,606 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB in Module to access Query Results

Hi,

I'm using Access 97.

I can run a query that finds a number of records, I then need to
access these results to build a formatted text file containing all of
the results. There will be 25 fields per record and potentially any
number of records.

I would have liked to have just produced a report sent to file but
formatted as I need. I don't think I can do this with a report as the
formatting gets messed up, so I think I really need to use VB to take
the results of the query and output them into the text file.

Can someone please give me a start in building the VB to access the
query and loop through the records.

Regards,

Bernard D
Aug 22 '06 #1
7 7276
If you can create a query that gives you the results you need, TransferText
would export it to a text file. No looping needed.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bernard D" <bd****@castlec s.co.ukwrote in message
news:ot******** *************** *********@4ax.c om...
Hi,

I'm using Access 97.

I can run a query that finds a number of records, I then need to
access these results to build a formatted text file containing all of
the results. There will be 25 fields per record and potentially any
number of records.

I would have liked to have just produced a report sent to file but
formatted as I need. I don't think I can do this with a report as the
formatting gets messed up, so I think I really need to use VB to take
the results of the query and output them into the text file.

Can someone please give me a start in building the VB to access the
query and loop through the records.

Regards,

Bernard D

Aug 22 '06 #2
On Tue, 22 Aug 2006 18:24:53 +0800, "Allen Browne"
<Al*********@Se eSig.Invalidwro te:
>If you can create a query that gives you the results you need, TransferText
would export it to a text file. No looping needed.
Yes, but the output file needs to have a specific format - one field
per line with blank lines where appropriate.

Does TransferText do that?
Aug 22 '06 #3
"Bernard D" <bd****@castlec s.co.ukwrote in message
news:ot******** *************** *********@4ax.c om...
Hi,

I'm using Access 97.

I can run a query that finds a number of records, I then need to
access these results to build a formatted text file containing all of
the results. There will be 25 fields per record and potentially any
number of records.

I would have liked to have just produced a report sent to file but
formatted as I need. I don't think I can do this with a report as the
formatting gets messed up, so I think I really need to use VB to take
the results of the query and output them into the text file.
Have you looked at using Mail Merge to output your data to Word?

Keith.
www.keithwilby.com
Aug 22 '06 #4
Okay, if you want to programmaticall y loop the records, exporting one field
per line, this is the basic idea:

Function ExportText() As Long
Dim rs As DAO.Recordset
Dim fld As DAO.Field

Open "C:\MyFile. txt" For Output As #1
Set rs = DBEngine(0)(0). OpenRecordset(" Query1")

Do While Not rs.EOF
For Each fld In rs.Fields
Print #1, fld.Name, fld.Value
Next
Print #1, "----------------"
rs.MoveNext
Loop

'Return the number of records exported.
ExportText = rs.RecordCount
rs.Close
Close #1
Set rs = Nothing
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bernard D" <bd****@castlec s.co.ukwrote in message
news:6m******** *************** *********@4ax.c om...
On Tue, 22 Aug 2006 18:24:53 +0800, "Allen Browne"
<Al*********@Se eSig.Invalidwro te:
>>If you can create a query that gives you the results you need,
TransferTex t
would export it to a text file. No looping needed.

Yes, but the output file needs to have a specific format - one field
per line with blank lines where appropriate.

Does TransferText do that?

Aug 22 '06 #5
On Tue, 22 Aug 2006 13:47:09 +0100, "Keith Wilby" <he**@there.com >
wrote:
>"Bernard D" <bd****@castlec s.co.ukwrote in message
news:ot******* *************** **********@4ax. com...
>Hi,

I'm using Access 97.

I can run a query that finds a number of records, I then need to
access these results to build a formatted text file containing all of
the results. There will be 25 fields per record and potentially any
number of records.

I would have liked to have just produced a report sent to file but
formatted as I need. I don't think I can do this with a report as the
formatting gets messed up, so I think I really need to use VB to take
the results of the query and output them into the text file.

Have you looked at using Mail Merge to output your data to Word?

Keith.
www.keithwilby.com
No. Mailmerge won't do.

This MUST be a text file, one field per line and 25 lines per record -
its for importing into a banking system, so it has to conform.

Thanks anyway,

Bernard D
Aug 22 '06 #6
On Tue, 22 Aug 2006 23:21:16 +0800, "Allen Browne"
<Al*********@Se eSig.Invalidwro te:
>Okay, if you want to programmaticall y loop the records, exporting one field
per line, this is the basic idea:

Function ExportText() As Long
....
>End Function
Many thanks that looks like I might be able to use it.

Cheers,

Bernard D
Aug 22 '06 #7
"Bernard D" <bd****@castlec s.co.ukwrote in message
news:gb******** *************** *********@4ax.c om...
On Tue, 22 Aug 2006 13:47:09 +0100, "Keith Wilby" <he**@there.com >
wrote:
>>>

Have you looked at using Mail Merge to output your data to Word?

Keith.
www.keithwilby.com
No. Mailmerge won't do.

This MUST be a text file, one field per line and 25 lines per record -
its for importing into a banking system, so it has to conform.
Fair enough, just a thought.

Keith.
Aug 23 '06 #8

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

Similar topics

8
2946
by: Frnak McKenney | last post by:
Back when computer dinosaurs roamed the earth and the precursors to today's Internet were tiny flocks of TDMs living symbiotically with the silicon giants, tracking access to data processing resources was much simpler: you logged in with a userID and password, and when you were done you ended your session by logging out (or occasionally by being disconnected). Connection time was easy to measure, and it made sense to both the customer...
0
2802
by: david liu | last post by:
access 2000 query: here's what i want to do. from an asp page, perform a search on a table in access. i have used sql code in the asp page itself, but i'd rather execute a query in access. i have success in running any query (basic SELECT, SELECT with conditions _other_ than LIKE, etc..) for some reason, when i execute the query below from the asp page, i get no results. the search.asp page just has a text box in a form that submits...
14
1843
by: CJM | last post by:
I have a query which produces different results in the Access query builder and in an ASP page (via ADO) An example of the query is: ---------------------------------------------------------- Select 'Ranked' as Source, H.HotelName, H.TelNo, H.URL, H.Location, H.HotelID, Rank from (Hotels H Inner Join PrefHotels P on H.HotelID = P.HotelID) Inner Join Locations L on P.LocID = L.LocID where Rank is not null and Rank > 0 and L.LocID=2
2
2384
by: Mattyboy | last post by:
Guys I have built a database with saved queries that runs fine in Access but when I call it from the web using ASP, an exception occurs. I have tried multiple ways of testing the databases with the following results. www.brinkster.com has a tool on their free asp hosting where you can dump an access .mdb database on there and then run SQL queries against it. Using Access databases it is possible to just call the query by using its...
1
308
by: dixie | last post by:
Just a general question to satisfy my natural curiosity. I have noticed that when I type Date() as part of a procedure behind a form, the () brackets drop off the end of it immediately I type them. It does, however appear to work as though they were there. Does this mean that I shouldn't use Date as a field name in a procedure as today's date - Date() ends up as Date after the brackets disappear? dixie
8
4028
by: Alfonso Esteban Gonzalez Sencion | last post by:
I am trying to use Access as a front end for extracting information from an Oracle database. I started using linked tables but I am getting a very curious behaviour. When I consult the linked table in access, the total number of records is OK but some records appear several times and some records do not appear at all. It seems as if access or the ODBC drivers returns several times the same record and skips some of the records, curiosly...
1
2485
by: zxo102 | last post by:
Hi everyone, I need your help for using python odbc module. I have a simple table defined as create table A ( userId char(10), courseid char(10), grade integer, primary key(userId,courseId) )
24
6092
by: Joe Salmeri | last post by:
I just upgraded from Python 2.4.2 to Python 2.5.1 and have found some unexpected behavior that appears to be a bug in the os.stat module. My OS is Windows XP SP2 + all updates. I have several programs that have worked flawlessly on all previous Python versions for years and they are now producing incorrect results in the code that uses os.stat. Searching through the 2.5.1 release notes I found the following:
21
34375
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
0
8009
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7939
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8432
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8428
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8078
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8299
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5962
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3919
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3964
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.