Displaying multiple pictures from different records on one form

TylerTand

Registered User.
Local time
Today, 06:29
Joined
Aug 31, 2007
Messages
95
Like the title says I need to have a form that displays up to 20 pictures of people. I have a subject table that includes a yes/no field I have named Add. I use this in a query to say Select * FROM Subject WHERE [Add] = True. This query allows me to select the people I want for the picture form. Now the hard part. How do I use the results of this query to populate a form that just has pictures? I don't want one continuous form because that will just give me a row of pictures. I want to have 4 rows of 5 photos. I can drag the picture field out of the list onto a blank form but that only works for one of the pictures. I also tried to put unbound boxes on the form for the other pictures but I don't know how to connect them to the query so that the pictures show up. When I set the record source to the picture field it populates all the boxes with the first picture. The list of people will change so I can't hard code a particular person's picture to the unbound box by Subject Record ID. If you guys can help with this you would really save me. Thanks:)
 
Not sure about dragging and dropping images, but in this example after you add a few images to the main form, clicking the browse button will display the images on one form.

Hope it helps your problem.

Dave
 

Attachments

If you want to connect each picture box to a picture you need to do this hardcoded. But you probably don't want that or you can use VBA.
1-You need to create all the picture boxes on your form and populate them using VBA.
The remaining empty picture boxes make them invisible.

2-Perhaps you can try a Crosstab query and bound the recordsource of the picture box to this query.

The first option works. The second i don't know.
 
Well there are several approaches depending on what the final purpose really is. I have 2 for u to try out:

1. Main Form with subform.

Here you create a hidden subform on your Pics form. The main form is unbound and the subform is bound to your query or table. This requires your base table to have a text field called PicPath, which holds the different paths to the different pics like this, more or less:
SubjectID.....PicPath
1.................C:\Pics\Pic1
2.................C:\Pics\Pic2
....
20...............C:\Pics\Pic20

These paths all appear in your subform.

Drag an image frame from the toolbox to your main form. A dialog appears, forcing u to choose an image. Choose a random image, then delete the path to this image and set the image type property to Linked. Make 19 copies of this image frame and name them sequentially like Pic1, Pic2.

Create a button btnAddPics and add this code to it's click event:
Private Sub btnAddPics_Click()
Dim picNum As Byte
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = Me.subfrm.Form.Recordset
rs.MoveFirst
picNum = 1
Do Until rs.EOF
Me("Pic" & picNum).Picture = rs!picPath
rs.MoveNext
picNum = picNum + 1
Loop
End Sub

Clicking the button will automatically load the 20 images into the 20 image frames. If u want these images to display every time you open the form, just put the code from btnAddPics in the forms Load or Current event.

2. Autonomous loading of Pictures

Delete the subform and all the code in the remaing form with the image frames. Add the following lines to the form's code:

Private Sub cboAddPic_Afterupdate()
Dim picNr As Byte
picNr = Me.cboAddPic
getPic (picNr)
End Sub

Sub getPic(picNum As Byte)
Dim result As Integer
Dim picName As String
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Select Picture"
.Filters.Add "All Files", "*.*"
.Filters.Add "JPEGs", "*.jpg"
.Filters.Add "Bitmaps", "*.bmp"
.FilterIndex = 3
.AllowMultiSelect = False
.InitialFileName = CurrentProject.Path
result = .Show
If (result <> 0) Then
picName = Trim(.SelectedItems.Item(1))
Me("PicPath" & picNum).SetFocus
Me("PicPath" & picNum) = picName
Me("Pic" & picNum).Picture = Me("PicPath" & picNum)
End If
End With
End Sub

Private Sub Comando16_Click()
Dim picNum As Byte
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = Me.subfrm.Form.Recordset
rs.MoveFirst
picNum = 1
Do Until rs.EOF
Me("Pic" & picNum).Picture = rs!picPath
rs.MoveNext
picNum = picNum + 1
Loop
End Sub

Private Sub Form_Current()
On Error Resume Next
Dim picNum As Byte
For picNum = 1 To 20
Me("PicPath" & picNum).Requery
Me("Pic" & picNum).Picture = Me("PicPath" & picNum)
Next picNum
End Sub

Create a table with 20 text fields and name them PicPath1, PicPath2....
Drag these 20 fields onto the form, but put them out of sight.

Next create a combobox cboAddPics. Set it's source type as list of values and it's rowsource like this:
1;Pic1;2;Pic2 ... 20;Pic20. Set number of columns to 2 and column widths to 0cm;2cm.

Set a reference to the Office Object Library

Now if u select a frame in the combobox, this will open a dialog, enabling you to choose an image for that frame on your HD. You can populate/change all image frames thru the combobox. You may also add some code enabling u to delet a pic.


HTH
Regards,
Premy
 

Users who are viewing this thread

Back
Top Bottom