troubleshooting Question

Pass a parameter from a button click event to a function...

Avatar of Fred Fisher
Fred FisherFlag for United States of America asked on
* MS Access VBA EventsDatabases* Access 2019
4 Comments1 Solution19 ViewsLast Modified:
Originally my database attached images to the database which made the image a part of the database which in turn inflated the size of the database.  I recently undertook the task to change these "attached images" and use the newer Image Control instead.

My form has three image controls FramePictureImage1, FramePictureImage2, and FramePictureImage3.  The corresponding fields for the image frames are FieldPictureImage1, FieldPictureImage2 and FieldPictureImage3.  The control source is PictureInstrument1, PictureInstrument2, and PictureInstrument3.

This so that whatever value is in the FieldPictureImage that is the image that is displayed in FramePictureImage.  Each Image frame has a Browse button so that you can look for the image that you want to display.  There are three buttons btnBrowsePicture1, btnBrowsePicture2 and btnBrowsePicture3.

Each button has for the click event PictureInstrument1(or 2 or 3) = PickFile1(or 2 or 3).  The PickFile is a Function so there are three functions PickFile1, PickFile2 and PickFile3.  Below is the code for PickFile1

Option Compare Database
Option Explicit
Public Function PickFile1() As String
     'Comments   : Select default root drive to search for media titles.
     'Parameters  :
     'Created       : 04/23/2021
     'Modified      : 08/18/2021
     'Copyright © 2021 Frederick W. Fisher, Jr.
     Dim FO As Object
     Dim strCurrentInstrumentImage1 As String
     Dim intRetval As Integer
     If IsNull(Me.PictureInstrument1) Then
          intRetval = MsgBox("Do you want to add a new image?", vbYesNo + vbQuestion + _
                 vbDefaultButton1, "<Network Connection Error>")
          Select Case intRetval
               Case vbYes
                    Set FO = Application.FileDialog(3)
                    FO.InitialFileName = "A:\Network Databases\Music Manager Database\InstrumentImages\"
               Case vbNo
          End Select
          strCurrentInstrumentImage1 = Me.PictureInstrument1
     End If
     Set FO = Application.FileDialog(3)
     FO.InitialFileName = "A:\Network Databases\Music Manager Database\InstrumentImages\"
     If FO.Show = -1 Then
          PickFile1 = FO.SelectedItems(1)
          If strCurrentInstrumentImage1 = "" Then
               MsgBox "No file was selected...", vbOKOnly, "Music Manager"
               MsgBox "No file was selected, original file will be restored...", vbOKOnly, "Music Manager"
               PickFile1 = strCurrentInstrumentImage1
          End If
     End If    
End Function

My question becomes is there a way to set up the Function so that I need only one function but I can get the parameter that the function needs from the click event of the Browse button so that I only need to one function instead of three?
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 4 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 4 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004