Solved

Importing various data types into Access'97 with user forms

Posted on 1998-10-19
2
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

630 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