Solved

Inserting the file path into a table

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

840 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