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
Else
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)
Else
If strCurrentInstrumentImage1 = "" Then
MsgBox "No file was selected...", vbOKOnly, "Music Manager"
Else
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?
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.