Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

import text file using Spec and export to XLS (2k format)

Status
Not open for further replies.

03Explorer

Technical User
Sep 13, 2005
304
US
I am trying to build a form that has a browse button to locate the file (filtered based on ascii formatted files 'asc') and then start the process of importing the file into Access using a spec for layout which also eliminates the primary key. Once import is done, an export to the same directory using the same file name but now as Excel 2000 format (XLS).

Is there such a tool or I could use help with two parts (as of now).

Browse button option does not seem to be as easy as I would like. then to import that file using a spec with the option of no primary key is the other part.

Ideas?
 
Here is a browse module (from Microsoft, as far as I recall). You will need an import specification. The second part will need DoCmd.TransferSpreadsheet.

Code:
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type

Function LaunchCD(frmForm As Form, strStartIn As String, strFilter As String) As String
    Dim OpenFile As OPENFILENAME
    Dim lReturn As Long
    'Dim strFilter As String
    

On Error GoTo HandleError

    OpenFile.lStructSize = Len(OpenFile)
    OpenFile.hwndOwner = frmForm.hwnd
    'sFilter = strFilter
    OpenFile.lpstrFilter = strFilter
    OpenFile.nFilterIndex = 1
    OpenFile.lpstrFile = String(257, 0)
    OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
    OpenFile.lpstrFileTitle = OpenFile.lpstrFile
    OpenFile.nMaxFileTitle = OpenFile.nMaxFile
    OpenFile.lpstrInitialDir = strStartIn
    OpenFile.lpstrTitle = "Select a file"
    OpenFile.flags = 0
    lReturn = GetOpenFileName(OpenFile)
        If lReturn = 0 Then
            'MsgBox "A file was not selected!", vbInformation, _
              "Select a file using the Common Dialog DLL"
            LaunchCD = ""
         Else
            LaunchCD = Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) - 1))
         End If
         
Exit_Sub:
    Exit Function
    
HandleError:
'Error code here
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top