Solved

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

Posted on 2014-11-22
2
449 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:
SimonAdept 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

708 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

18 Experts available now in Live!

Get 1:1 Help Now