I'm attempting to give users the opportunity to specify the file name for a text export. I've put the code on the unload event of a form. Ideally, when the user clicks the "close" button, they are promted as to whether they want to export to a text file. If they select yes, then they are prompted for a file name.
What actually happens is the filename is "strFileName" with the "date" and ".txt" added. I don't know what happens to the name that is entered in the input box.
I need a solution and guidance as to why this isn't working like I expected.
Here is my code:
Private Sub Form_Unload(Cancel As Integer)
Dim Msg, Style, Title, Response
Msg = "Do you want to export to a text file?"
Style = vbYesNoCancel
Title = "Export?"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Dim strFileName As String
strFileName = InputBox("Please enter a file name." & vbCrLf & "The date will automatically be added to your filename."
DoCmd.TransferText acExportDelim, , "qselInterestedIndividuals", "\\Consumer Database\Text Exports\strFileName" & " - " & Date$ & ".txt"
MsgBox "Your file has been saved to the TEXT EXPORTS subdirectory in the Consumer Database directory." & vbCrLf & " The current date has been added as part of the filename", , "Export Complete"
ElseIf Response = vbNo Then
Else
DoCmd.CancelEvent
End If
End Sub
TIA
Melanie
What actually happens is the filename is "strFileName" with the "date" and ".txt" added. I don't know what happens to the name that is entered in the input box.
I need a solution and guidance as to why this isn't working like I expected.
Here is my code:
Private Sub Form_Unload(Cancel As Integer)
Dim Msg, Style, Title, Response
Msg = "Do you want to export to a text file?"
Style = vbYesNoCancel
Title = "Export?"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Dim strFileName As String
strFileName = InputBox("Please enter a file name." & vbCrLf & "The date will automatically be added to your filename."
DoCmd.TransferText acExportDelim, , "qselInterestedIndividuals", "\\Consumer Database\Text Exports\strFileName" & " - " & Date$ & ".txt"
MsgBox "Your file has been saved to the TEXT EXPORTS subdirectory in the Consumer Database directory." & vbCrLf & " The current date has been added as part of the filename", , "Export Complete"
ElseIf Response = vbNo Then
Else
DoCmd.CancelEvent
End If
End Sub
TIA
Melanie