Solved

Importing various data types into Access'97 with user forms

Posted on 1998-10-19
2
303 Views
Last Modified: 2008-02-26
I am having trouble importing data into Access'97 via user forms. I previously used the following functions in Access 2.0 but it doesn't convert to Access'97.

Function ImportData ()

Dim filename As String
Dim strDir As String
Dim strImportDir As String

strImportDir = "C:\LPP\DBASE\INPUT\"

    strDir = CurDir$
   
    If strDir = strImportDir Then
        GoTo FindFile
    Else
        If Left(strDir, 1) = Left(strImportDir, 1) Then
            ChDir Mid(strImportDir, 3)
        Else
            ChDrive Left(strImportDir, 2)
            ChDir Mid(strImportDir, 3)
        End If
    End If
   
FindFile:
    filename = GetImportFile()             ' Display Open File dialog.
    filename = Trim(filename)
    If filename = "" GoTo ImportData_Cancel   ' User pressed Cancel.
   
    ImportData = filename

ImportData_Cancel:

End Function


Private Function GetImportFile () As String
    '  Return path of data file chosen by user in OpenFile dialog box.
    '  (This function works in conjunction with GetMDBName2 and StringFromSz to
    '  display a File-Open dialog that prompts user for location of data file.
    '  It uses code found in WZLIB.MDA.)

    Const OFN_SHAREAWARE = &H4000
    Const OFN_PATHMUSTEXIST = &H800
    Const OFN_HIDEREADONLY = &H4

    Dim OFN As wlib_GetFileNameInfo

    '  Fill ofn structure which is passed to wlib_GetFileName
    OFN.hWndOwner = 0
    OFN.szFilter = "All Files (*.*)|*.*|All Files (*.*)|*.*|"
    OFN.NFilterIndex = 1
    OFN.szTitle = "Where is Import Data?"
    OFN.Flags = OFN_SHAREAWARE Or OFN_PATHMUSTEXIST Or OFN_HIDEREADONLY
    OFN.szDefExt = "*"

    '  Call wlib_GetFileName function and interpret results.
    If (GetImportFile2(OFN, True) = False) Then
        GetImportFile = StringFromSz(OFN.szFile)
    Else
        GetImportFile = ""
    End If

End Function


Private Function GetImportFile2 (gfni As wlib_GetFileNameInfo, ByVal fOpen As Integer) As Long
    '  This function acts as a cover to MSAU_GetFileName in MSAU200.DLL.
    '  wlib_GetFileName terminates all strings in gfni structure with nulls and
    '  then calls DLL version of function.  Upon returning from MSAU200.DLL, null
    '  characters are removed from strings in gfni.
   
    Dim lRet As Long

    gfni.szFilter = RTrim$(gfni.szFilter) & Chr$(0)
    gfni.szCustomFilter = RTrim$(gfni.szCustomFilter) & Chr$(0)
    gfni.szFile = RTrim$(gfni.szFile) & Chr$(0)
    gfni.szFileTitle = RTrim$(gfni.szFileTitle) & Chr$(0)
    gfni.szInitialDir = RTrim$(gfni.szInitialDir) & Chr$(0)
    gfni.szTitle = RTrim$(gfni.szTitle) & Chr$(0)
    gfni.szDefExt = RTrim$(gfni.szDefExt) & Chr$(0)

    lRet = wlib_MSAU_GetFileName(gfni, fOpen)

    gfni.szFilter = StringFromSz(gfni.szFilter)
    gfni.szCustomFilter = StringFromSz(gfni.szCustomFilter)
    gfni.szFile = StringFromSz(gfni.szFile)
    gfni.szFileTitle = StringFromSz(gfni.szFileTitle)
    gfni.szInitialDir = StringFromSz(gfni.szInitialDir)
    gfni.szTitle = StringFromSz(gfni.szTitle)
    gfni.szDefExt = StringFromSz(gfni.szDefExt)

    GetImportFile2 = lRet


End Function



Private Function StringFromSz (szTmp As String) As String
    '  If string terminates with nulls, return a truncated string.
    Dim ich As Integer
    ich = InStr(szTmp, Chr$(0))
    If ich Then
        StringFromSz = Left$(szTmp, ich - 1)
    Else
        StringFromSz = szTmp
    End If
End Function

0
Comment
Question by:Moyura
2 Comments
 
LVL 5

Accepted Solution

by:
chewhoung earned 100 total points
ID: 1965889
I've a MDB with form that get file name from the file dialog box. Let me know your email address here so I can mail to you.
0
 

Author Comment

by:Moyura
ID: 1965890
My e-mail address is moyura_asi@hotmail.com
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question