Solved

Importing various data types into Access'97 with user forms

Posted on 1998-10-19
2
291 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now