You call the WriteToFile procedure in the Click event procedure of a button
on the form. The procedure requires the path to the file to be created as
its argument so to call it you need to follow the name of the procedure with
the path to the file this could be a literal path, e.g.
WiteToFile "C:\MyFiles\MyFile.txt"
but more usually you would be able to assign a path at runtime. This could
be entered in a text box on the form as I suggested so you'd then reference
the text box:
WriteToFile Me.txtPath
or you could allow the user to browse to the file by opening a common
dialogue with the button and assigning the path selected by the user in the
dialogue. You can download code for opening a common dialogue from many
places but the one I normally use is Bill Wilson's BrowseForFileClass class
module which van be obtained from:
http://community.netscape.com/n/pfx...yMessages&tsn=1&tid=22415&webtag=ws-msdevapps
Having installed Bill's module in your database the code for the button's
Click event procedure to open it, assign the selected path to a text box
txtPath, and call the WriteToFile procedure could be:
On Error GoTo Err_Handler
Dim OpenDlg As New BrowseForFileClass
Dim strPath As String
Dim strAdditionalTypes As String
Dim strMessage As String
Dim blnOverwrite As Boolean
blnOverwrite = True
' open common dialogue to browse to file
OpenDlg.DialogTitle = "Select File"
OpenDlg.AdditionalTypes = _
"Text Files (*.txt; *.csv; *.tab; *.asc) |*.txt; *.csv; *.tab; *.asc"
strPath = OpenDlg.GetFileSpec
Set OpenDlg = Nothing
Me.txtPath = strPath
' get user confirmation of write operation
strMessage = "Write data to file " & strPath & "?"
If MsgBox(strMessage, vbYesNo + vbQuestion, "Confirm Write Operation") =
vbYes Then
' if file already exists get user confirmation to overwrite it
If Dir(strpath) <> "" Then
strMessage = "File " & strpath & " already exists. Overwrite?"
If MsgBox(strMessage, vbYesNo + vbQuestion, "Confirm Overwrite")
= vbNo Then
blnOverwrite = False
End If
End If
' call procedure to write data to file if overwrite confirmed
' or file doesn't already exist
If blnOverwrite Then
WriteToFile strpath
End If
End If
Exit_here:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error"
Resume Exit_here
You don't actually need the text box for this, but you might feel it better
for the user to see the path on the form rather than merely in the message
box.
Ken Sheridan
Stafford, England
Kirt84 said:
Hi
I have done the coding for the 'write to file' but I am unsure of what you
mean about what should go in the command buttons procedure.