Hi There,
I am currently doing a project for college where I need to make a database to display pictures.
I have based it on the Northwinds Database but customized it for my needs.
The Database can be found here
What I have is a Hotel form which displays pictures of hotels, currently there are no pictures are on it, but you can add your own if you want...
I have the delete button which once clicked completely deletes the picture without any prompting.
The only prompting i have been able to make is a message box which just simply says "Warning! You have just deleted the picture of the hotel" press ok to continue , and not OK and Cancel. Is it possible to do such a thing.
The VB code i have is shown below, the code separated with dashes is what were looking at.
Thanks for your help
Ben
I am currently doing a project for college where I need to make a database to display pictures.
I have based it on the Northwinds Database but customized it for my needs.
The Database can be found here
What I have is a Hotel form which displays pictures of hotels, currently there are no pictures are on it, but you can add your own if you want...
I have the delete button which once clicked completely deletes the picture without any prompting.
The only prompting i have been able to make is a message box which just simply says "Warning! You have just deleted the picture of the hotel" press ok to continue , and not OK and Cancel. Is it possible to do such a thing.
The VB code i have is shown below, the code separated with dashes is what were looking at.
Code:
Option Compare Database
Option Explicit
Dim path As String
Private Sub AddPicture_Click()
' Use the Office File Open dialog to get a file name to use
' as an employee picture.
getFileName
End Sub
Private Sub Command89_Click()
End Sub
Private Sub Delehotel_DblClick()
On Error GoTo Err_Delehotel_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit_Delehotel_Click:
Exit Sub
Err_Delehotel_Click:
MsgBox Err.Description
Resume Exit_Delehotel_Click
End Sub
Private Sub Form_RecordExit(Cancel As Integer)
' Hide the errormsg label to reduce flashing when navigating
' between records.
errormsg.Visible = False
End Sub
------------------------------------------------------------------------
Private Sub RemovePicture_Click()
' Clear the file name for the employee record and display the
' errormsg label.
MsgBox "Warning! You have just deleted the picture of the hotel"
Me![ImagePath] = ""
hideImageFrame
errormsg.Visible = True
End Sub
------------------------------------------------------------------------
Private Sub ImagePath_AfterUpdate()
' After selecting an image for the employee, display it.
On Error Resume Next
showErrorMessage
showImageFrame
If (IsRelative(Me!ImagePath) = True) Then
Me![ImageFrame].Picture = path & Me![ImagePath]
Else
Me![ImageFrame].Picture = Me![ImagePath]
End If
End Sub
Private Sub Form_Current()
' Display the picture for the current employee record if the image
' exists. If the file name no longer exists or the file name was blank
' for the current employee, set the errormsg label caption to the
' appropriate message.
Dim res As Boolean
Dim fName As String
path = CurrentProject.path
On Error Resume Next
errormsg.Visible = False
If Not IsNull(Me!Photo) Then
res = IsRelative(Me!Photo)
fName = Me![ImagePath]
If (res = True) Then
fName = path & "\" & fName
End If
Me![ImageFrame].Picture = fName
showImageFrame
Me.PaintPalette = Me![ImageFrame].ObjectPalette
If (Me![ImageFrame].Picture <> fName) Then
hideImageFrame
errormsg.Caption = "Picture not found"
errormsg.Visible = True
End If
Else
hideImageFrame
errormsg.Caption = "Click Add/Change to add picture"
errormsg.Visible = True
End If
End Sub
Sub getFileName()
' Displays the Office File Open dialog to choose a file name
' for the current employee record. If the user selects a file
' display it in the image control.
Dim fileName As String
Dim result As Integer
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Select Hotel 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
fileName = Trim(.SelectedItems.Item(1))
Me![ImagePath].Visible = True
Me![ImagePath].SetFocus
Me![ImagePath].Text = fileName
Me![FirstName].SetFocus
Me![ImagePath].Visible = False
End If
End With
End Sub
Sub showErrorMessage()
' Display the errormsg label if the image file is not available.
If Not IsNull(Me!Photo) Then
errormsg.Visible = False
Else
errormsg.Visible = True
End If
End Sub
Function IsRelative(fName As String) As Boolean
' Return false if the file name contains a drive or UNC path
IsRelative = (InStr(1, fName, ":") = 0) And (InStr(1, fName, "\\") = 0)
End Function
Sub hideImageFrame()
' Hide the image control
Me![ImageFrame].Visible = False
End Sub
Sub showImageFrame()
' Display the image control
Me![ImageFrame].Visible = True
End Sub
Private Sub Delehotel_Click()
On Error GoTo Err_Delehotel_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit_Delehotel_Click:
Exit Sub
Err_Delehotel_Click:
MsgBox Err.Description
Resume Exit_Delehotel_Click
End Sub
Private Sub butdelhotel_DblClick()
On Error GoTo Err_butdelhotel_DblClick
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit_butdelhotel_DblClick:
Exit Sub
Err_butdelhotel_DblClick:
MsgBox Err.Description
Resume Exit_butdelhotel_DblClick
End Sub
Private Sub delhotel_Click()
On Error GoTo Err_delhotel_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit_delhotel_Click:
Exit Sub
Err_delhotel_Click:
MsgBox Err.Description
Resume Exit_delhotel_Click
End Sub
Thanks for your help
Ben
Last edited: