|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
||||
|
||||
|
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
|
|
#3
|
|||
|
|||
|
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? |
|
#4
|
||||
|
||||
|
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
|
|
#5
|
|||
|
|||
|
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? |
|
#6
|
||||
|
||||
|
Make sure that you have Microsoft ActiveX Database Objects v2.x selected as a reference in your project.
|
|
#7
|
|||
|
|||
|
yep got it thanks heaps!
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > vba looping to print out unique files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|