Skip to content

Instantly share code, notes, and snippets.

@kissmygritts
Created November 17, 2015 23:13
Show Gist options
  • Save kissmygritts/b499d39b827472a71f58 to your computer and use it in GitHub Desktop.
Save kissmygritts/b499d39b827472a71f58 to your computer and use it in GitHub Desktop.
.CSV output for all collar data
Sub csv_output()
Dim rs As DAO.Recordset
Dim sql As String
Dim fso As Object, csv As Object
Dim l As String
sql = "SELECT * FROM Query3"
Set rs = CurrentDb.OpenRecordset(sql)
Set fso = CreateObject("Scripting.FileSystemObject")
Set csv = fso.createtextfile("C:\Users\Mgritts\Documents\AllCollars.csv")
rs.MoveFirst
csv.writeline "locid, ndowid, timestamp, long_x, lat_y, hdop, species, mgmtarea, deviceid"
With rs
Do Until .EOF
l = !locid & "," & !ndowid & "," & !timestamp & "," & !long_x & "," & !lat_y & "," & !hdop & "," & !spid & "," & !mgmtarea & "," & !deviceid
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