Skip to content

Instantly share code, notes, and snippets.

@kissmygritts
Created May 29, 2015 21:45
Show Gist options
  • Save kissmygritts/ec5567b0acc7d487d6b0 to your computer and use it in GitHub Desktop.
Save kissmygritts/ec5567b0acc7d487d6b0 to your computer and use it in GitHub Desktop.
Write CSV file from recordset. Used this because N(records) > what access can handle.
Sub data_output()
Dim rs As DAO.Recordset
Dim sql As String
Dim fso As Object, csv As Object
Dim l As String
sql = "SELECT z_dev_collars.Diagnoses, tbl_gps_locations.timestamp, tbl_gps_locations.long_x AS geox, tbl_gps_locations.lat_y AS geoy FROM z_dev_collars LEFT JOIN tbl_gps_locations ON z_dev_collars.Collar_Current_ID = tbl_gps_locations.deviceid WHERE (((tbl_gps_locations.timestamp) Is Not Null));"
Set rs = CurrentDb.OpenRecordset(sql)
Set fso = CreateObject("Scripting.FileSystemObject")
Set csv = fso.createtextfile("C:\Users\Mgritts\Documents\collars2.txt")
With rs
Do Until .EOF
l = !Diagnoses & "," & !timestamp & "," & !geox & "," & !geoy & ",DD"
csv.writeline l
.MoveNext
Loop
End With
rs.Close
csv.Close
Set fso = Nothing
Set csv = Nothing
Set rs = Nothing
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment