Solved

Inserting the file path into a table

Posted on 2003-10-28
5
893 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
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.

736 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