Solved

Inserting the file path into a table

Posted on 2003-10-28
5
888 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

685 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