Results 1 to 9 of 9

Thread: Open/select multiple file from MS access

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    263

    Question Open/select multiple file from MS access

    Hi,

    Does anybody know what syntax to be used in opening multiple file in VBA ms access and store the file path?

    Normally what I do inside MS excel vba is by using:

    Code:
    files = Application.GetOpenFilename("Excel Files (*.xls), *.xls", , , , True)
    
    For i = 1 To UBound(files)
    
    next i
    I need this one coz I need to select multiple files (ex. xl,txt)

    Thanks
    "Its easy to teach FAITHFUL MAN to be ABLE than ABLE MAN to be FAITHFUL"

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Open/select multiple file from MS access

    This is how I do it.

    Thread Moved

    Code:
    Dim strFile As String
    Application.FileDialog(msoFileDialogOpen).Filters.Add "Images", "*.gif; *.jpg, *.png", 1
    lret = Application.FileDialog(msoFileDialogOpen).Show
    If lret = -1 Then
        strFile = Application.FileDialog(msoFileDialogOpen).SelectedItems.Item(1)
    End If
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    263

    Question Re: Open/select multiple file from MS access

    I just tested it, but why the vba gives me an error:

    Run-time-error

    Method 'FileDialog' of object '_Application' failed?

    Do i need to activate something in the reference here?

    Thanks
    "Its easy to teach FAITHFUL MAN to be ABLE than ABLE MAN to be FAITHFUL"

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Open/select multiple file from MS access

    "_Application" are you using VB.NET or ??? FileDoalog is available at least back to Office XP (2002).
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    263

    Re: Open/select multiple file from MS access

    No. Im applying it to MS access 2003
    "Its easy to teach FAITHFUL MAN to be ABLE than ABLE MAN to be FAITHFUL"

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Open/select multiple file from MS access

    You should have a reference preset to Office 11.0 since this is in Access 2003 but its basic Access code and shouldnt be failing.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    263

    Question Re: Open/select multiple file from MS access

    Hi,

    Yah I think I miss adding the Microsoft Office 11.0. Ithought it would work on already on Microsoft Access 11.0 library.

    But anyway how can I make this code for selection of Multiple entry. I can select multiple files but the value of "lret" always = to -1?

    How can I create a loop to make and run with every file I select?

    Thanks in advance
    "Its easy to teach FAITHFUL MAN to be ABLE than ABLE MAN to be FAITHFUL"

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Open/select multiple file from MS access

    Should be like...

    Application.FileDialog(msoFileDialogOpen).Multiselect = True

    Then iterate through the .SelectedItems collection.

    Note: I am typing all this in the reply box so may be slightly off a bit.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    263

    Thumbs up Re: Open/select multiple file from MS access

    Hi little correction. SHould be

    Application.FileDialog(msoFileDialogOpen).AllowMultiSelect

    I figured it out already oepning multiple selection file.

    Thanks so much!!!!
    "Its easy to teach FAITHFUL MAN to be ABLE than ABLE MAN to be FAITHFUL"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width