Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Importing various data types into Access'97 with user forms

Posted on 1998-10-19
2
Medium Priority
?
309 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 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

971 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