Solved

Storing the selected item from a file lookup to a text box field

Posted on 2014-11-22
2
452 Views
Last Modified: 2014-11-22
This solution below worked like it was supposed to.

However, I have been trying to modify the output to store the selected strFilePath into text box data.

I have a form that the user inputs a lot of data which get stored in to text boxes.  The values in the text boxes are used in a Query Update.  I would like to get the strFilePath into a form text box that can be accessed by my query.

What do I need to modify in the following?  I tried storing the strFilePath to a TempVar.

Thanks

Glen



Private Sub cmdAttachFile_Click()
Dim rsFile As DAO.Recordset
Dim strFilePath As String, strFilename As String
strFilePath = fSelectFile()
If strFilePath & "" <> "" Then
strFilename = Mid(strFilePath, InStrRev(strFilePath, "\") + 1)
    With CurrentDb.OpenRecordset("tblFileAttachments")
        .AddNew
        !RecordID = Me.txtMainID
        !FilePath = strFilePath
        !FileName = strFilename
        .Update
    End With
End If
End Sub

Function fSelectFile()
Dim fd As Object
Set fd = Application.FileDialog(3)
With fd
    .InitialFileName = CurrentProject.Path & "\"
    .AllowMultiSelect = False
    .ButtonName = "Select"
    .InitialView = 2
    .Title = "Select File"

    'display file dialog box
    If .Show Then
          fSelectFile = .SelectedItems(1)
    Else
        Exit Function
    End If

End With
End Function
0
Comment
Question by:GPSPOW
2 Comments
 
LVL 18

Accepted Solution

by:
Simon earned 500 total points
ID: 40460005
Modify the sub to write to the textbox just before it exits. In this example it assumes you have created a textbox control called "txtFilePath".

Private Sub cmdAttachFile_Click()
Dim rsFile As DAO.Recordset
Dim strFilePath As String, strFilename As String
strFilePath = fSelectFile()
If strFilePath & "" <> "" Then
strFilename = Mid(strFilePath, InStrRev(strFilePath, "\") + 1)
    With CurrentDb.OpenRecordset("tblFileAttachments")
        .AddNew
        !RecordID = Me.txtMainID
        !FilePath = strFilePath
        !FileName = strFilename
        .Update
    End With
End If
me.txtFilePath = strFilePath
End Sub

Open in new window


After running the sub by clicking "cmdAttachFile" the file path will be in that textbox, which you can refer to as a parameter value from your query, assuming the form is still open when you run your query. If the form will NOT be open but the textbox is bound to underlying table, you can lookup the value from the table as part of your query.
0
 

Author Closing Comment

by:GPSPOW
ID: 40460019
Thank you

Worked great

Glen
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

863 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

21 Experts available now in Live!

Get 1:1 Help Now