Results 1 to 5 of 5
  1. #1
    Jaron is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    63

    FileDialogFilePicker Filter type returning 'Argument not optional' error

    Here is some code I have for importing an excel binary into my DB as a table. It is supposed to allow the user to choose the file location to import from. I need it to replace, not append to the existing table of the same name. After the user makes a selection, it temporarily renames the existing table for safety, then imports the file under the correct name. Lastly it deletes the original table that was renamed. The run-around is so that if there is a hang-up I don't end up losing the original.



    I want to filter the File Dialog box so that the user can only choose files of the correct type. The line that is supposed to do that hangs up though. If I comment it out, everything else runs smoothly. Here's what I have:

    Code:
    Option Explicit
    Public Sub Import()
        
         Dim dlgSlct As FileDialog
         Dim strInputFileName As String
         Set dlgSlct = Application.FileDialog(msoFileDialogFilePicker)
         With dlgSlct
            .InitialFileName = CurrentProject.Path
            .InitialView = msoFileDialogViewDetails
            .Filters = "Excel Files (*.xlsb)"
            .AllowMultiSelect = False
            .Title = "Choose a file to import"
         End With
         
         dlgSlct.Show
         
         If dlgSlct.SelectedItems.Count > 0 Then
         
            strInputFileName = dlgSlct.SelectedItems(1)
            DoCmd.Rename "Original Table1", acTable, "Table1"
            DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "Table1", _
            strInputFileName, True, "Table1"
            DoCmd.DeleteObject acTable, "Original Table1"
            
            MsgBox "Import complete"
            
        Else
        
            MsgBox "Data was not imported"
            
        End If
        
    End Sub

    The module is called through a command button on a form which is coded with the following:

    Code:
    Private Sub Command33_Click()
    On Error GoTo Command33_Click_Err
    Run "Import"
    Command33_Click_Exit:
        Exit Sub
    Command33_Click_Err:
        MsgBox Error$
        Resume Command33_Click_Exit
    End Sub
    Any thoughts on this?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,967
    Try:
    .Filters.Clear
    .Filters = "Excel Files", "*.xlsb"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Jaron is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    63
    Nope. It doesn't like that. It flags a compile error on the comma: 'expected end of statement'. The only way I can make it stick is with: "Excel Files *.xlsb"
    Then when I run it I get the same error as before: 'Argument not optional.' hung on the '.Filters' argument.
    Is there any chance I set references to the wrong library? I added in the MSO 14.0 Object Library to get the FilePicker in the first place, but it almost seems as though it doesn't understand the 'Filters' part of it. But then, the 'Filters.Clear' seems to work ok.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,967
    Sorry, was not paying attention. Here is the correct syntax:

    .Filters.Add "Excel Files", "*.xlsb"

    http://msdn.microsoft.com/en-us/libr...ffice.11).aspx
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Jaron is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    63
    I thought I'd tried that one already, but I guess not because it worked. Thanks!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. error argument not optional
    By slimjen in forum Programming
    Replies: 10
    Last Post: 03-20-2013, 09:31 PM
  2. Compile Error: Argument not optional
    By tariq1 in forum Programming
    Replies: 4
    Last Post: 08-11-2012, 01:06 PM
  3. Replies: 7
    Last Post: 11-17-2011, 02:56 PM
  4. byref argument type mismatch error
    By karuppasamy in forum Access
    Replies: 1
    Last Post: 06-22-2011, 09:37 AM
  5. Compile Error: Argument Not Optional
    By bg18461 in forum Access
    Replies: 1
    Last Post: 12-01-2010, 08:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums