Results 1 to 2 of 2
  1. #1
    seleese is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    1

    ahtCommonFileOpenSave filename issue

    Hi,



    I'm proper stuck with some code I'm trying to change. Basically, I have a query which returns one record that I need to include in the Save as section of my FileOpenSave dialog box rather than it being blank. So for example once the dialog windows appears I want it to be complete with UK20111204 automatically rather than the user naming the file themselves.

    The code works fine without trying to add the filename but once I try to incorporate it doesn't like it.

    My Current code:
    Code:
    Function Export()
    On Error GoTo Export_Err
      
    Dim strFilter As String
    Dim strInputFileName As String
    Dim Fname As String
    Fname = "UK" & TC_DATE!qry_TC_DATE
    'qry and field name
    
      
      strFilter = ahtAddFilterItem(strFilter, "Text Files (*.TXT)", "*.TXT")
      strInputFileName = ahtCommonFileOpenSave( _
                    Filename:= Fname,
                    Filter:=strFilter, OpenFile:=True, _
                    DialogTitle:="Please select a location to Export to", _
                    Flags:=ahtOFN_HIDEREADONLY)
      
      If Len(strInputFileName) > 0 Then
        DoCmd.TransferText acExportFixed, "Export Specification", "05_qry_Export_final", strInputFileName, False, ""
      End If
      
    Export_Exit:
      Exit Function
      
    Export_Err:
      MsgBox Error$
      Resume Export_Exit
      
    End Function
    It's highlighted as red from line strInputFileName = ahtCommonFileOpenSave ( _

    I in desperate need of help!!

    Many thanks in advance for your help!!

    SEL

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I found several things that needed correcting: a line continuation character was missing, the Flags parameter was set to open a file & the OpenFile parameter was set to open (not save) the file.

    (I also renamed the file name variable.)

    Try this:

    Code:
    Function Export()
       On Error GoTo Export_Err
    
       Dim strFilter As String
       Dim strSaveAsFileName As String
       Dim Fname As String
       Fname = "UK" & TC_DATE!qry_TC_DATE
       'qry and field name
    
    
       'Ask for SaveAsFileName
       strFilter = ahtAddFilterItem(strFilter, "Text Files (*.TXT)", "*.TXT")
       strSaveAsFileName = ahtCommonFileOpenSave( _
                          Filename:=Fname, _
                          Filter:=strFilter, _
                          OpenFile:=False, _
                          DialogTitle:="Please select a location to Export to", _
                          Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY)
    
       If Len(strSaveAsFileName) > 0 Then
          DoCmd.TransferText acExportFixed, "Export Specification", "05_qry_Export_final", strSaveAsFileName, False, ""
       End If
    
    Export_Exit:
       Exit Function
    
    Export_Err:
       MsgBox Error$
       Resume Export_Exit
    
    End Function
    If this line

    Code:
    Fname = "UK" & TC_DATE!qry_TC_DATE
    creates the file name you want, then I think the code should save the file......

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

Similar Threads

  1. Variuse FileName When Export
    By shay in forum Import/Export Data
    Replies: 1
    Last Post: 12-01-2010, 11:36 AM
  2. Date and time in filename
    By frankesjoberg in forum Import/Export Data
    Replies: 1
    Last Post: 03-02-2010, 12:35 PM
  3. Filename displaying with image
    By Rob Parker in forum Forms
    Replies: 2
    Last Post: 01-13-2010, 05:05 PM
  4. Prompt for filename for import/export??
    By stephenaa5 in forum Import/Export Data
    Replies: 23
    Last Post: 10-23-2009, 03:43 PM
  5. Replies: 0
    Last Post: 06-11-2009, 01:54 PM

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