(This is in Access 2003.) I am writing a macro that opens up a form to allow users enter the path and name of the file they wish to import. Then it closes the form, and imports the data in the specified file. I have the code that opens the form and user input properly. I also have the code that does the import/manipulation of data once I get the path and file name.
My question is: how do I use the information entered in the form in the macro/other subs after the form is closed?
Here's the simple version of my form's code ("Enter Import Info"):
Option Compare Database
Option Explicit
Sub RunButton_Click()
FilePathTextBox.SetFocus
DataPath = FilePathTextBox.Text
FileNameTextBox.SetFocus
DataName = FileNameTextBox.Text
DoCmd.Close
End Sub
Here's the simple version of my macro attempt (which failed):
Option Compare Database
Option Explicit
Option Base 1
Public DataPath As String
Public DataName As String
Public CompleteName As String
Function StartImport()
'Open form to let user enter import file info
DoCmd.OpenForm "Enter Import Info", acNormal, , , , acDialog
'Get complete file path/name. I think this is where the problem is.
CompleteName = DataPath & "\" & DataName
'Import
ImportData
'Data clean up
DataCleanup
End Function
Function ImportData()
'Import CompleteName
'The import code here works fine when CompleteName has the right info
End Function
Sub DataCleanup()
'cleans up the data as needed (using DoCmd.RunSQL). Works fine.
End Sub
I spent more than 2 hours looking on the Internet for solutions, but couldn't find one. A friend suggests creating a temp table to store the values entered in the form as a string (meaning the table will have only 1 field and 1 record). But I don't know how to retrieve it as a string out of the table.
Sorry for the very long post - I wanted to be as clear as possible. Thank you for your help in advance!!
==============Edit (Additional information)
The original code in the form asks the user to manually type in the path and file name. The entire code was working back then.
However, I wanted to avoid mistakes/errors by using FileDialog to determine the path and name, so I created subs that are called when the textbox is clicked(FileNameTextBox_Click and FilePathTextBox_Click). The code for FileNameTextBox_Click() can be found here: FileDialog doesn't work
Does that affect anything?