Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Me.lstOutputFields.RowSource = Me.lstOutputFields.RowSource & _
";" & _
Me.lstAvailableFields.ItemData(Me.lstAvailableFields.ListIndex)
Dim conCurrent As ADODB.Connection
Dim rstOutput As New ADODB.Recordset
Dim objField As ADODB.Field
Dim intFile As Integer
Dim strSQL As String, strDataLine As String
Set conCurrent = CurrentProject.Connection
'Turn lstOutputFields.RowSource into a valid SQL string
strSQL = Replace(Me.lstOutputFields.RowSource, ";", ", ")
strSQL = "SELECT " & strSQL & " FROM " & Me.lstAvailableFields.RowSource & ";"
'Open the output file C:\Output.csv
intFile = FreeFile
Open "C:\Output.csv" For Output As #intFile
'Open the recordset defined by the form
rstOutput.Open strSQL, conCurrent, adOpenForwardOnly, adLockReadOnly
'Create and write the header line
strDataLine = Chr(34) & "," & Chr(34)
strDataLine = Chr(34) & Replace(Me.lstOutputFields.RowSource, ";", strDataLine) & Chr(34)
Print #intFile, strDataLine
'Now loop through the recordset and write a CSV line for each record
Do
For Each objField In rstOutput.Fields
strDataLine = strDataLine & Chr(34) & "," & Chr(34) & objField.Value
Next objField
strDataLine = Chr(34) & strDataLine & Chr(34)
Print #intFile, strDataLine
strDataLine = ""
rstOutput.MoveNext
Loop Until rstOutput.EOF
rstOutput.Close
Close #intFile
Set rstOutput = Nothing
Set conCurrent = Nothing