Solved

Inserting the file path into a table

Posted on 2003-10-28
5
873 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
ID: 9635167
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
ID: 9635584
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
ID: 9652113
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
ID: 9993137
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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.

803 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