You can allow Client’s to insert their own logo on the Switchboard or Main Menu (and, if you like Reports). This is especially a nice touch as Clients will be able to personalize the file as their own.
The first thing you will need is a separate table the holds the Company Profile information, Figure 1. (Note: I do not store the image in the database but do allow Users to navigate to the image storing only the path to the image.
Second, is a to place an Image Control on the form and/or reports and set *Picture to (NONE)* and *Size Mode to Zoom*, Figure 2. (For the purpose of this example, my Image Control is named imgLogo.)
Third, add a Command Button to your form to *get the Image*. Mine has a little camera on it and is named cmdAddImage. Then place Call GetImage in the On_Click event…
Private Sub cmdAddImage_Click()
Call GetImage
End Sub
GetImage code from my modUtilities…
Public Sub GetImage() Dim fDialog As Object Dim varFile As Variant ' Set up the File Dialog. Set fDialog = Application.FileDialog(3) With fDialog ' Allow user to make multiple selections in dialog box .AllowMultiSelect = False ' Set the title of the dialog box. ' .Title = "Please select file to add..." ' Clear out the current filters, and add our own. .Filters.Clear .Filters.Add "Compressed Image Files", "*.jpg, *.gif, *.png" .Filters.Add "Uncompressed Image Files", "*.bmp, *.wmf" .Filters.Add "All Files", "*.*" .InitialFileName = "C:\" ' Show the dialog box. If the .Show method returns True, the ' user picked at least one file. If the .Show method returns ' False, the user clicked Cancel. If .Show = True Then varFile = .SelectedItems.Item(1) Forms![frmInputCompanyProfile]![txtImagePath] = Mid(varFile, InStrRev(varFile, "\") + 1) Else MsgBox "You clicked Cancel in the file dialog box." End If End With End Sub
Fourth, add a Command Button to your form to *remove the Image*. Mine has a little circle with a line thru it and is named cmdClearImage. Then place the below in the On_Click event…
Private Sub cmdClearImage_Click()
On Error Resume Next 'Lazy mans error handling Me.txtImagePath = Null Me.imgImage.Picture = ""
End Sub
Fifth, add the below to the frmCompanyProfile’s On_Open event…
Private Sub Form_Current()
On Error Resume Next 'Lazy mans error handling If IsNull([txtImagePath]) Then Exit Sub Me.imgImage.Picture = Me.txtImagePath
End Sub
Sixth, add an Image Control, naming it imgLogo to all the Forms and/or Reports you want your Logo to be displayed on.
And finally, place the code below in the On_Open event of your Forms and/or Reports to get the logo to show, as shown in Figure 3…
If IsNull(DLookup("[cpImagePath]", "tblCompanyProfile")) Then Exit Sub Me.imgLogo.Picture = DLookup("[cpImagePath]", "tblCompanyProfile")
P.S. Another example using a different format can be found at my website, Customize your Main Menu (Switchboard).
2,457 total views, 1 views today