Need Code Help - Docmd. problem

  • Thread starter Thread starter lcannon1
  • Start date Start date
L

lcannon1

The first code "DirectorySelect works fine. I need help with th
second piece"Files in Directory_Click() please. I am leaving somethin
out and do not know what it is. I need for the second part to do th
docmd.transfer.... when I click on the file I found in the first part.
Can someone look at it and help me with what I am missing??? Thanks

Private Sub cmd_DirectorySelect_Click()

Dim strValue As String
Dim strFoundFile As String

If Me.txt_SelectedDirectory = "" _
Or IsNull(Me.txt_SelectedDirectory) _
Then
Me.txt_SelectedDirectory = BrowseFolder
Else
Dim strStartDirectory As String
strStartDirectory = BrowseFolder(""
CStr(Me.txt_SelectedDirectory))
Me.txt_SelectedDirectory = strStartDirectory
End If

If Me.txt_SelectedDirectory = "" _
Or IsNull(Me.txt_SelectedDirectory) _
Then
Me.txt_SelectedDirectory = "C:\"
End If

strFoundFile = Dir(Me.txt_SelectedDirectory & "/*.*")
Do Until strFoundFile = ""
strValue = strValue & strFoundFile & ";"
strFoundFile = Dir
Loop

Me.lst_FilesInDirectory.RowSourceType = "Value List"
Me.lst_FilesInDirectory.RowSource = strValue

Me.txt_SelectedDirectory.Visible = True
Me.lst_FilesInDirectory.Visible = True
Me.lbl_NextStep.Visible = True
Me.grp_OpenStatus.Visible = True

End Sub

Private Sub lst_FilesInDirectory_Click()
Dim TableName As String
Dim fs As Object
' Declare filesearch object.
Set fs = Application.FileSearch

' Set folder to search. This example assumes that the files reside
' in the C:\Documents and Settings\a-fell\Desktop folder.
fs.LookIn = ParseDirectory(strFile)

' Set file name to search for. This example assumes that you
' want to search for .txt files.
fs.FileName = strSearchName & "*.txt"

' Execute the file search, and check to see if the file(s) ar
present.
If fs.Execute > 0 Then

TableName = GetFileName(TableName)

fHandleFile Me.txt_SelectedDirectory & "/"
Me.lst_FilesInDirectory, Me.grp_OpenStatus
DoCmd.TransferSpreadsheet acImport, 0, TableName, , True
End Su
 
Lcannon1,

I am not able to comment on all of your code, as you are using a lot of
stuff I am not familiar with. But I noticed a couple of things...

1. It looks like there is no End If to complete the segment beginning
If fs.Execute > 0 Then

2. The DoCmd.TransferSpreadsheet statement appears to be missing a
couple of elements. You have a 0 in the place of the spreadsheet type
argument... I am not sure what this signifies and whether it is valid.
And you have nothing in the File Name argument, which would be necessary.
 
Back
Top