In your life, you may have a lot of photos that you took with your family, friends, or co-workers. These photos are very good memory. Of course, you can keep your photos in hard copy album and place it in your house. But you are probably difficult when you stay away from home and want to see those photos. It is a good idea to have your photos album stored in your personal computer. In this page, you will learn how to create your photo collection in Ms. Access 2007 by yourself. First, open Ms. Access 2007 database and create form(PhotosCollection). Then, drop 4 command buttons as shown above. You also need to drag and drop 1 image control on the form to display your photo. To store the data of your photos paths, please create a table and name it as tblphoto(ID,Photopath). After naming these controls (you may name them as used in the code below. Otherwise, it doesn't work), use the following code for cmdadd button click and Photopath textbox(a field of tblphoto table) got focus events :
Option Compare Database
Private Sub cmdadd_Click()
Dim fdialog As Office.FileDialog
Dim fs As Variant
'create filedilog object
Set fdialog = Application.FileDialog(msoFileDialogFilePicker)
.Filters.Add "Ms.Access Files", "*.jpg; *.bmp; *.gif", 1
If .Show Then
fs = .SelectedItems(1)
If fs <> "" Then
DoCmd.RunMacro "Macro1" 'add new record if a file was selected
Photopath.Value = fs 'add selected value to textbox
'clear filedialog object
Set fdialog = Nothing
Private Sub Photopath_GotFocus()
On Error Resume Next
Me.imgphoto.Picture = Me.Photopath.Value
To move the photo forward or backward, click on forward button ( > ) or backward button (< ).
It is not necessary to write code for these control. You can create these control by wizard.
To delete the photo, click on delete button (Delete image). You also can create this button by wizard.
To add a new photo, click on Add image button that needs some codes as shown above. To make record set ready to add a new record, you need to create a macro(Macro1) with GotoRecord action.
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: