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