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
Solved

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

Posted on 2014-11-22
2
456 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

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…
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 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…
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…

829 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