Hi everyone,
I am a newbie to VB and making great use of various web resources to find answers. However, the simple topics don't seem to be covered anywhere.
Here goes. I have some code that opens the windows open file dialog box and prompts the user to locate the file. The file string is then stored in the variable varFileName. So far so good. I then want to use the file name in a DoCmd.TransferT ext command to get the text file into my database.
How do I pass the variable (which is stored as K:etcetcetcetc/etc.csv) into the TransferText command?
Heres the code, thanks in advance, Stuart
Private Sub cmdImport3_Clic k()
Call OpenTextFile
DoCmd.TransferT ext acImportFixed, "Daily Rental Analysis Import Specification", _
"CM Daily Rental Report", "How do I get the bold bit below in here???"
MsgBox ("The file was imported")
End Sub
Public Function OpenTextFile(Op tional varDirectory As Variant) As Variant
Dim strFilter As String, lngFlags As Long, varFileName As Variant
lngFlags = ahtOFN_FILEMUST EXIST Or _
ahtOFN_HIDEREAD ONLY Or ahtOFN_NOCHANGE DIR
If IsMissing(varDi rectory) Then
varDirectory = ""
End If
strFilter = ahtAddFilterIte m(strFilter, "csv files (*.csv)", "*.csv")
strFilter = ahtAddFilterIte m(strFilter, "Any files (*.*)", "*.*")
varFileName = ahtCommonFileOp enSave( _
OpenFile:=True, _
InitialDir:=var Directory, _
Filter:=strFilt er, _
Flags:=lngFlags , _
DialogTitle:="O pen a csv file ...")
If Not IsNull(varFileN ame) Then
varFileName = varFileName
End If
OpenTextFile = varFileName
End Function
I am a newbie to VB and making great use of various web resources to find answers. However, the simple topics don't seem to be covered anywhere.
Here goes. I have some code that opens the windows open file dialog box and prompts the user to locate the file. The file string is then stored in the variable varFileName. So far so good. I then want to use the file name in a DoCmd.TransferT ext command to get the text file into my database.
How do I pass the variable (which is stored as K:etcetcetcetc/etc.csv) into the TransferText command?
Heres the code, thanks in advance, Stuart
Private Sub cmdImport3_Clic k()
Call OpenTextFile
DoCmd.TransferT ext acImportFixed, "Daily Rental Analysis Import Specification", _
"CM Daily Rental Report", "How do I get the bold bit below in here???"
MsgBox ("The file was imported")
End Sub
Public Function OpenTextFile(Op tional varDirectory As Variant) As Variant
Dim strFilter As String, lngFlags As Long, varFileName As Variant
lngFlags = ahtOFN_FILEMUST EXIST Or _
ahtOFN_HIDEREAD ONLY Or ahtOFN_NOCHANGE DIR
If IsMissing(varDi rectory) Then
varDirectory = ""
End If
strFilter = ahtAddFilterIte m(strFilter, "csv files (*.csv)", "*.csv")
strFilter = ahtAddFilterIte m(strFilter, "Any files (*.*)", "*.*")
varFileName = ahtCommonFileOp enSave( _
OpenFile:=True, _
InitialDir:=var Directory, _
Filter:=strFilt er, _
Flags:=lngFlags , _
DialogTitle:="O pen a csv file ...")
If Not IsNull(varFileN ame) Then
varFileName = varFileName
End If
OpenTextFile = varFileName
End Function
Comment