Results 1 to 8 of 8
  1. #1
    Datament is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2023
    Posts
    39

    msoFileDialogSaveAs not responding

    I'm using a button "btnProcess" to save an excel file using MSOFileDialogSaveAS vba to open a file path for users to save to a folder in the open path or from there navigate to a desired path of the user. Below is what I have designed to open the path to \Acctstmt.

    Every time I press btnProcess I get the error message "Compile error: Variable not Defined" highlighting "Set FDir = Application.FileDialog (msoFileDialogSaveAs)" in the vba code editor.

    Please can you kindly review the below and please advise of what I am doing wrong or give me some suggestions related to MSOFileDialogSaveAs.

    Dim MyExpFilename As String
    Dim MyExpPath As String
    Dim FDir As Object ' Used Object type instead of STRING for late binding
    Dim strQ As String
    Dim strF As String
    Dim TempF As String
    Dim OpenF_Path As String
    Dim ExportF_Excel As String
    Dim AppEx As Object ' Used Object type instead of STRING for late binding'
    Dim myWork As Object ' Used Object type instead of STRING for late binding

    TempF = "C:\RedGrows\ScheduledAcct\AcctStmt"

    strQ = Chr$(34)
    ExportF_Excel = "\8 Excel-" & Me.GetStore & Me.Ref
    MyExpFilename = TempF & ExportF_Excel
    OpenF_Path = strQ & TempF & "" & ExportF_Excel & ".xlsx" & strQ

    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "qry_myCSVWork_Union", MyExpFilename, True

    Set AppEx = CreateObject("Excel.Application")
    Set myWork = AppEx.Workbooks.Open(OpenF_Path)
    AppEx.Visible = True

    With myWork
    ' Display Save As dialog to choose new location
    Set FDir = Application.FileDialog(msoFileDialogSaveAs) 'Compile Error message highlights this line in the code editor
    With FDir
    .InitialFileName = MyExpFilename
    If .Show = -1 Then
    MyExpPath = .SelectedItems(1)

    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "qry_myCSVWork_Unin", MyExpPath, True


    End If
    End With
    myWork.Close True
    End With

    Set AppEx = Nothing
    Set myWork = Nothing

    Kill (TempF & "" & ExportF_Excel & ".xlsx")

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    You are using late binding, so the object has no idea as to what Application.FileDialog msoFileDialogSaveAs is, so either make it early binding, or find out what Application.FileDialog msoFileDialogSaveAs is as a numeric and use that.
    Your choice?

    BTW it would never be a string. It is an object, be it early/late bound
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Make sure you have this reference set:

    Click image for larger version. 

Name:	ref.png 
Views:	25 
Size:	50.6 KB 
ID:	52038

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    TBH I have never found any definitive source as to what you need to include as a reference when trying to use functions like these? :-(
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    The object browser will often tell you.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Quote Originally Posted by Micron View Post
    The object browser will often tell you.
    You need the reference loaded to be able to see that? and that is the issue, which reference?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Thanks to Micron, that value is 2
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    Well ain't that dumb? An object browser that doesn't browse objects you haven't already have a connection to. Not the most intuitive at times, but I often go here to fill in the blanks.
    https://learn.microsoft.com/en-us/of.../api/overview/
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Database not responding
    By keith2511 in forum Programming
    Replies: 8
    Last Post: 06-07-2018, 04:32 PM
  2. Window Not Responding
    By GbJubes in forum Forms
    Replies: 2
    Last Post: 12-21-2015, 07:36 AM
  3. Access Not Responding
    By bigspace55 in forum Queries
    Replies: 1
    Last Post: 02-28-2013, 01:02 PM
  4. Access Not Responding
    By Phoenyxsgirl in forum Access
    Replies: 11
    Last Post: 11-25-2011, 11:40 AM
  5. Query Not Responding
    By Lady_Jane in forum Queries
    Replies: 9
    Last Post: 11-09-2010, 01:27 PM

Tags for this Thread

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