by Michael Shively AKA MidnightElf (1 Submission)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 30th March 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This code exports data from the DataGrid control to a *.csv file for MS Excel. This might not be perfect but it's a good start and it's more
With dlgCommonDialog
.DialogTitle = "Save"
.CancelError = False
'ToDo: set the flags and attributes of the common dialog control
.Filter = "MS Excel CSV Files (*.csv)|*.csv" ' save as csv file
.ShowSave
If Len(.FileName) = 0 Then
Exit Sub
End If
sFile = .FileName
End With
'MsgBox sFile 'display the file path and name if desired.
Open sFile For Append As #1 'open the specified file
Dim strRecInfo As String
For i = 1 To adoPrimaryRS.RecordCount 'loop through records
For j = 0 To Me.grdDataGrid.Columns.Count - 1 'loop through columns
strRecInfo = strRecInfo & Me.grdDataGrid.Columns(j).Value & "," 'make data comma delimited
Next j
Print #1, strRecInfo
strRecInfo = ""
adoPrimaryRS.MoveNext
Next i
Close #1
No comments have been posted about This code exports data from the DataGrid control to a *.csv file for MS Excel. This might not be pe. Why not be the first to post a comment about This code exports data from the DataGrid control to a *.csv file for MS Excel. This might not be pe.