Linking Images to Combo-Box selections

mca2k4

Registered User.
Local time
Yesterday, 18:04
Joined
Jul 6, 2005
Messages
14
I currently have a form with a drop-down combo box that is used as a tool for selecting an employee's last name. After selecting a name, the text boxes below the combo box are updated to match up with the selected name.

However, I am trying to get the employee images to do the same thing, but it's not working. The employee photos are currently "Bound Object Frame" items. Any suggestions/help would be greatly appreciated.

Thanks in advance. :)
 
If I get the jest of what you want to do.

Do you want to make a selection by viewing the persons image by useing a ComboBox. If so, to my knowledge that not going to happen for you directly,ComboBoxes are not made to do that.

Give a little detail of want exacly you want to do. I've done something like what you are describing (I believe), and I'll work it to your needs.
 
Has the NorthWind sample db offered any suggestions? They do something similar.
 
I think this is what you want?
Have a look at the arrached sample - not my work- found it on the web somewhere.

When you unzip the folder make sure that you put the database and the bmp's into the same folder then create a new folder called PlayerLogo and put all the bmp's in that folder.

Example: (put the database in this folder)

C:\Temp\

make a new folder:(put the bmp's into the folder called PlayerLogo.

C:\Temp\PlayerLogo

If you open the form in design view and look at the code behind the combo box you will see what has to be done.
 

Attachments

I looked at the Northwind.mdb database and that one has pictures linked to records that must be gone through using the nav buttons on the bottom nav bar.


Thanks ansentry, what you attached is exactly what I'm talking about. The only problem is that my bitmaps are already embedded into the database as part of a table (and I dont want to deal with the hassle of having linked images).

here is the code for the attachment:
Code:
Private Sub Form_Current()
Dim strPath As String
Dim strDir As String

If Nz(Len(Me.PlayLogo), 0) > 0 Then
strPath = CurrentProject.Path & "\PlayerLogo\" & Me.PlayLogo
strDir = Dir(strPath)
If Dir(strPath) <> "" Then
Me.ImgPlaylogo.Picture = strPath
Me.ImgPlaylogo.Visible = True
Me.LblplayLogo.Visible = False
End If
Else
Me.ImgPlaylogo.Visible = False
Me.LblplayLogo.Visible = True
End If
End Sub

Private Sub Combo42_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[Name] = '" & Me![Combo42] & "'"
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    Me.Combo42 = Null
End Sub

I've already adapted the Combo42_AfterUpdate() code to fit my form/combo box; however, I'm not sure how to go about altering the Form_Current code because it assumes the image files are located in a specific folder path. I'd like this to simply go to already-embedded images in the database. Any suggestions? :confused:
 
mca2k4,

You state:
Code:
My bitmaps are already embedded into the database as part of a table

Just my opion but I would not leave it like that, your database will become very big. Store them the same as the sample.
 
I've only got a couple very small bitmaps (~160x160 pixels). Therefore I'd still prefer to keep them embedded in the database; is there way to change the code posted earlier to make it work w/ embedded instead of linked bitmaps?
 
I tried going w/ the linked way and adapted the sample db's code to look like this:

Code:
 Option Compare Database
Option Explicit

Private strSQL As String

Private Sub Form_Current()
Dim strPath As String
Dim strDir As String

If Nz(Len(Me.EmpLogo), 0) > 0 Then
strPath = CurrentProject.Path & "\EmployeeLogo\" & Me.EmpLogo
strDir = Dir(strPath)
If Dir(strPath) <> "" Then
Me.ImgEmplogo.Picture = strPath
End If
End Sub

Private Sub Form_Load()
Me.FirstName = Me.EmpList.Column(2)
End Sub

Private Sub EmpList_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[LastName] = '" & Me![EmpList] & "'"
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub


However, now I'm getting the error message "Run-time error '52': Bad files name or number". I checked the file name and path for everything, and all the employee image files are located in a subdirectory called "EmployeeLogo" within the folder where the database is located. :confused:
 
Where are you getting the error? (What line is highlighted)

I have copied your code to my sample and it works fine. I did not use the On Load because I don't know what it suppose to do.
 
Thanks for all your help ansentry. I think I'm going to do some more work on digging out a way to leave the bitmaps embedded and somehow access them from within the database itself. Thanks again! :)
 
Have a look at this attached sample.

When you first open it go to tables and open the table (only 1)

Enter the path of your images, give them a name.

You will notice that I have


C:\accessimages\NP.jpg


as 1 of my entries, this is used by the code if there is No Picture.

What image you use for this is up to you, me I used a ? from clipart.

When you have done this you can open the form and all will be well .............."Optimist"

The images and the database do not have to be in the same folder (directory) with this example.

If you have any problems then post back to the forum.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom