First Many thanks to you all for trying very to assist on how to save string from MS Access to a text file, however, there are still a few things remaining to get it right, the file to save is giving a debug error when trying save. Could it be I'm going off the line again?
Private Sub CmdServings_Click()Dim strData As StringDim n As IntegerDim dlg As filedialogDim GetFilePath As Object Set dlg = Application.filedialog(msoFileDialogSaveAs) dlg.AllowMultiSelect = False dlg.Title = "Select the file to be imported..." If dlg.Show Then GetFilePath = dlg.SelectedItems(1) End Ifn = FreeFile()Print #n, strDataClose #nEnd Sub
Private Sub CmdServings_Click()Dim strData As StringDim n As IntegerDim dlg As filedialogDim GetFilePath As Object Set dlg = Application.filedialog(msoFileDialogSaveAs) dlg.AllowMultiSelect = False dlg.Title = "Select the file to be imported..." If dlg.Show Then GetFilePath = dlg.SelectedItems(1) End Ifn = FreeFile()Open GetFilePath For Output As #nPrint #n, strDataClose #nEnd Sub
Though some other errors will follow next, GetFilePath should be string, strData is empty etc etc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
ASKER
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
ASKER
I have also tried to load strData with some manual data so that it does not show empty but still the debug error pops up.
Private Sub CmdServings_Click()Dim strData As StringDim n As IntegerDim dlg As filedialogDim GetFilePath As ObjectstrData = "145236tyyiio" Set dlg = Application.filedialog(msoFileDialogSaveAs) dlg.AllowMultiSelect = False dlg.Title = "Select the file to be export..." If dlg.Show Then GetFilePath = dlg.SelectedItems(1) End Ifn = FreeFile()Open GetFilePath For Output As #nPrint #n, strDataClose #nEnd Sub
You should use a file picking function and simply use the returned value. This simplifies your code, allow reuse, make your code much more dependable. I urge you to simply use a function like https://www.devhut.net/2016/10/04/late-binding-the-filedialog/
Kimputer
Also thanks for marking your own answer, while my FIRST POST said:
Open in new window
Though some other errors will follow next, GetFilePath should be string, strData is empty etc etc