Guest User

Untitled

a guest
Oct 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. Set db = CurrentDb
  2.  
  3. 'Check to see if querydef exists
  4. For i = 0 To (db.QueryDefs.Count - 1)
  5. If db.QueryDefs(i).Name = "Sheet1" Then
  6. db.QueryDefs.Delete ("Sheet1")
  7. Exit For
  8. End If
  9. Next i
  10.  
  11. Set qd = db.CreateQueryDef("Sheet8", exportSQL)
  12.  
  13. 'Set intial filename
  14. fd.InitialFileName = "export_" & Format(Date, "mmddyyy") & ".csv"
  15.  
  16. If fd.Show = True Then
  17. If Format(fd.SelectedItems(1)) <> vbNullString Then
  18. DoCmd.TransferText acExportDelim, "Standard Output ", "Sheet1", fd.SelectedItems(1), False
  19. End If
  20. End If
  21.  
  22. 'Cleanup
  23. db.QueryDefs.Delete "Sheet1"
  24. db.Close
  25. Set db = Nothing
  26. Set qd = Nothing
  27. Set fd = Nothing
  28.  
  29. End Sub
Add Comment
Please, Sign In to add comment