-1

I have written a code in which data is written to a csv file where the filename and pathname are hardcoded , is it possible to make the button save the file to a user specific location ? Help would be appreciated . Thank you Below is the code of what i have done

Public Sub exportCSV()

    MyRes.MoveFirst  
    strCsvFile = "D:\Mycsv.csv"

    fHndl = FreeFile

        Open strCsvFile For Output As fHndl
         out2 = MyRes.GetFieldNameAt(1)
          Print #fHndl, out2
    MyRes.MoveFirst
     While Not MyRes.IsEOF

        out = MyRes.GetField("ID")
'        Debug.Print out2
       Print #fHndl, out
        MyRes.MoveNext
    Wend

    MsgBox ("Downloaded")

    Close #fHndl

End Sub
user1
  • 13
  • 2
  • 5
  • You can do this using Common Dialog. See an example of the save here: http://www.developerfusion.com/code/211/common-dialog-example/ Or here: http://www.vb6.us/tutorials/common-dialogs-vb-tutorial – Fred Aug 12 '16 at 11:50
  • Thank you . That helped ,but where exactly in my function would i be able to use it ? – user1 Aug 12 '16 at 12:06

1 Answers1

1

You need to insert it prior to assigning your filename. Eg

MyRes.MoveFirst

CommonDialog1.InitDir = "C:\MyStartFolder"
CommonDialog1.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*"
CommonDialog1.ShowSave

strCsvFile = CommonDialog1.FileName

fHndl = FreeFile

You should include a check that the file name returned is valid.