Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old August 11th, 2003, 05:29 AM
ashley1 ashley1 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Manchester
Posts: 15 ashley1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
vba looping to print out unique files

hi

i have a database in access 2000 which has one table called addresses with 2 columns called "id" and "first name"
i want to print out each record into indivudal .html files
so far i can pick each row and write them to one file! but i want to loop through this code and print out each row giving its unique file name!

my coding so far is:-

Private Sub Command1_Click()

Dim rs As ADODB.Recordset
Dim strConnect As String
Dim strSQL As String
Dim str As String
Dim columnSep As String
Dim rowSep As String
columnSep = vbTab
rowSep = vbCrLf

' Begin Test data set-up
strSQL = "SELECT * FROM Addresses"
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\vb\db\db1.mdb"
' End Test data setup

Set rs = New ADODB.Recordset

rs.Open strSQL, strConnect

str = RTrim(rs.GetString(, , columnSep, rowSep, ""))
rs.Close
Open "c:\vb\db\output.txt" For Output As #1
Print #1, str
Close 1

End Sub


can any1 help?

Reply With Quote
  #2  
Old August 11th, 2003, 08:04 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,834 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 30 m 30 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Code:
rs.Open strSQL, strConnect
rs.MoveFirst
While not rs.EOF
     str = rs!TheFieldName
     ' or
     str = rs.Fields("TheFieldName").Value

     Open str For Output As #1
    'write the other fields here
    Close #1
    rs.MoveNext
Wend

Reply With Quote
  #3  
Old August 11th, 2003, 08:52 AM
ashley1 ashley1 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Manchester
Posts: 15 ashley1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks that worked

but im not familar with vba just a begginer so how would i write the other fileds name, would i just list them?
(say i have id and name)

also i get files with no extension format could i replace .value with .html?

Reply With Quote
  #4  
Old August 11th, 2003, 10:13 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,834 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 30 m 30 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
No, you'll have to add the extension manually.

Try something like this:
Code:
Dim sId as String
Dim sName as String
Dim sFile as String

rs.Open strSQL, strConnect
rs.MoveFirst
While not rs.EOF
	 'read in the fields from the current recordset row
     sId = rs.Fields("id").Value
	 sName = rs.Fields("name").Value

	 sFile = sId & ".txt" 'adding the file extension
     Open sFile For Output As #1
	 print #1, sId
	 print #1, sName
     Close #1
     rs.MoveNext
Wend

Reply With Quote
  #5  
Old August 12th, 2003, 06:51 AM
ashley1 ashley1 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Manchester
Posts: 15 ashley1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks that was good and worked fine

but i did this as a little test now that im trying to put it into my big real database i get compile error saying user-defined type not defined! and highlights Dim rs As ADODB.Recordset
im not sure what im doing wrong?

any help?

Reply With Quote
  #6  
Old August 12th, 2003, 07:32 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,834 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 30 m 30 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Make sure that you have Microsoft ActiveX Database Objects v2.x selected as a reference in your project.

Reply With Quote
  #7  
Old August 12th, 2003, 10:14 AM
ashley1 ashley1 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Manchester
Posts: 15 ashley1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
yep got it thanks heaps!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > vba looping to print out unique files


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway