Solved

Inserting the file path into a table

Posted on 2003-10-28
5
853 Views
Last Modified: 2012-05-04
I am developing an access database which records the details of specific in-house data analysis jobs carried out by information staff.
I want to include some sort of function where the user clicks a button and can navigate ( maybe via a file-browser-type box?) to the file(s) they have created, and selecting it inserts it into the path field for that job in the main table.

Any help would be greatly appreciated.
0
Comment
Question by:accipiter123
5 Comments
 
LVL 8

Expert Comment

by:MrRobin
Comment Utility
This sounds very similar to another recent question...

    http://www.experts-exchange.com/Databases/MS_Access/Q_20768650.html

...hope this helps!
0
 
LVL 8

Accepted Solution

by:
dds110 earned 500 total points
Comment Utility
Paste this into a new module:

'******************Start Code**************************
Public Declare Function GetOpenFileName Lib "comdlg32.dll" _
    Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Public Type OPENFILENAME
        lStructSize As Long
        hwndOwner As Long
        hInstance As Long
        lpstrFilter As String
        lpstrCustomFilter As String
        nMaxCustFilter As Long
        nFilterIndex As Long
        lpstrFile As String
        nMaxFile As Long
        lpstrFileTitle As String
        nMaxFileTitle As Long
        lpstrInitialDir As String
        lpstrTitle As String
        flags As Long
        nFileOffset As Integer
        nFileExtension As Integer
        lpstrDefExt As String
        lCustData As Long
        lpfnHook As Long
        lpTemplateName As String
End Type

Public Function OpenFile() As String
'API reference is "GetOpenFileName" using comdlg32.dll
    On Error GoTo Error_OpenFile
   
    Dim MyPath As String
    Dim app As Application
    Dim FileOpen As Variant
    Dim rc As Long
    Dim pOpenfilename As OPENFILENAME
   
    Const MAX_BUFFER_LENGTH = 256
    MyPath = CurrentDb.Name
   
With pOpenfilename
    .hwndOwner = Screen.ActiveForm.hwnd
    .hInstance = 1
    .lpstrTitle = "Open"
    .lpstrInitialDir = MyPath
    .lpstrFilter = "All Files" & Chr$(0) & "*.*" & Chr$(0)
    .nFilterIndex = 1
    .lpstrFile = String(MAX_BUFFER_LENGTH, 0)
    .nMaxFile = MAX_BUFFER_LENGTH - 1
    .lpstrFileTitle = .lpstrFile
    .nMaxFileTitle = MAX_BUFFER_LENGTH - 1
    .lStructSize = Len(pOpenfilename)
End With

rc = GetOpenFileName(pOpenfilename)

If rc Then
    'A file has been selected
    FileOpen = Left$(pOpenfilename.lpstrFile, pOpenfilename.nMaxFile)
   
Else
    'The cancel button has been pressed
    FileOpen = ""
End If

OpenFile = FileOpen

Exit_OpenFile:
    Exit Function
   
Error_OpenFile:
    MsgBox Err.Description, 0, Err.Number
    Resume Exit_OpenFile:
End Function
'*****************End Code************************

Usage:

Sub cmdButton_Click()
    MsgBox OpenFile
End Sub

HTH
0
 

Expert Comment

by:andygua
Comment Utility
I'm not sure if it's the same as before, but you could try the following link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnima01/html/ima1101.asp

It's an API that replaces the common dialog, which for me works very well.
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: dds110 {http:#9635584}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

stevbe
EE Cleanup Volunteer
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

728 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

12 Experts available now in Live!

Get 1:1 Help Now