Please Help With File Dialog Syntax (1 Viewer)

TBC

Registered User.
Local time
Today, 14:12
Joined
Dec 6, 2010
Messages
145
Hi,

Can one of you pros take a look at this code and help get the bugs out?

Compile error: Invalid outside procedure / syntax error
Compile error: Sub or Function not defined

Visual Basic for Applications
Microsoft Access 16.0 Object Library
OLE Automation
Microsoft Office 16.0 Object Library

I'm trying to create a folder browser that will let the user go to the folder, pick the excel file and import it into access them into a table in access then run a couple questions to get it formatted do some calculations and export it back out with the same name it came in as


---------------------------------------------------------------------------------------------------------
Code:
Private Sub cmdShow_Click()
On Error GoTo SubError
**** 'Add "Microsoft Office 16.0 Object Library" in references
    Dim fdialog As Office.FileDialog
    Dim varfgile As Variant
    
    txtSelectedName = ""
    
**** ' Set up the File Dialog
****Set fdialog = Application.FileDialog(msoFileDialogFilePicker)

  
     
    With fdialog
********.Title = "Choose the spreadsheet you would like to import"
********.AllowMultiSelect = False
********.InitialFileName = "C:\Users\cvlasa1\Downloads\SelfTrade\Export to Excel\" 'Folder picker needs trailing slash
        
        .Filters.Clear
********.Filters.Add "Excel files", "*.xls*"
'*******.Filters.Add "Excel files", "*.xls"
'*******.Filters.Add "Excel files", "*.xlsx"
'*******.Filters.Add "Excel macro-enabled", "*.xlsm"
*
*******     If .Show = True Then
*******     If .SelectedItems.Count = 0 Then
**************** 'User clicked open but didn't select a file
****************GoTo SubExit
**********
        End If
**********
************ 'An option for MultiSelect = False
************ 'varFile = .SelectedItems(1)
************ 'txtSelectedName = varFile
**********
************ 'Needed when MultiSelect = True
************For Each varFile In .SelectedItems
****************txtSelectedName = txtSelectedName & varFile & vbCrLf
************Next
********
        Else
************ 'user cancelled dialog without choosing!
************ 'Do you need to react?
********End If
**
****End With
**
SubExit:
On Error Resume Next
****Set fdialog = Nothing
****Exit Sub
**
SubError:
****MsgBox "Error Number: " & Err.Number & " = " & Err.Description, vbCritical + vbOKOnly, _
********"An error occurred"
****GoTo SubExit
******
End Sub
 

Attachments

  • Database2.accdb
    376 KB · Views: 507
  • 2017-10-24_14-22-48.jpg
    2017-10-24_14-22-48.jpg
    89.7 KB · Views: 530
  • References.jpg
    References.jpg
    78.9 KB · Views: 494

TBC

Registered User.
Local time
Today, 14:12
Joined
Dec 6, 2010
Messages
145
Thanks MarKK for your post. When asking for help should I only post on one form?

I see you have 256 Posts. Do they all start with: "Cross posted:"
 

MarkK

bit cruncher
Local time
Today, 14:12
Joined
Mar 17, 2004
Messages
8,181
Thanks MarKK for your post. When asking for help should I only post on one form?

I see you have 256 Posts. Do they all start with: "Cross posted:"
I believe that cross-posts should be indicated. If I see cross-posts that are not indicated, I provide such indication.

You are most welcome,
Mark
 

Users who are viewing this thread

Top Bottom