Solved

Importing various data types into Access'97 with user forms

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

910 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

24 Experts available now in Live!

Get 1:1 Help Now