• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

Global Images in forms

I have a number of images on a form that I open hidden that holds all the images for a number of different departments.

Such as:-

BCImage1
BCImage2
BCImage3
GRImage1
GRImage2
GRImage3 etc.

If a user is logged on and navigates to the Home page then the image associated with the users department is displayed on the home page, which could be BCImage1 or GRImage1 etc.

I have populated the form with bound images that I have linked to images in a folder where the Back End tables are stored.

I have the following code that is in the OpenForm event

If sDepartment = "Grounds Department" Then
         Me.FolderImage.PictureData = Forms!subfrmSystemImages!GRImage1.PictureData
    ElseIf sDepartment = "Bar and Catering" Then
         Me.FolderImage.PictureData = Forms!subfrmSystemImages!BCImage1.PictureData
    ElseIf sDepartment = "Sportshall" Then
         Me.FolderImage.PictureData = Forms!subfrmSystemImages!SHImage1.PictureData
    ElseIf sDepartment = "Administration" Then
         Me.FolderImage.PictureData = Forms!subfrmSystemImages!ADImage1.PictureData
    ElseIf sDepartment = "Reception" Then
         Me.FolderImage.PictureData = Forms!subfrmSystemImages!REImage1.PictureData
    ElseIf sDepartment = "Facilities" Then
         Me.FolderImage.PictureData = Forms!subfrmSystemImages!FAImage1.PictureData
    End If

The problem I am getting is that when opening the database using the login, I get a warning message to say that the Db can't find the form with the images (I assume because it is hidden)

However When a user with particular access opens the database to a different for without images then the form loads ok hidden. However if the user then goes to the home page then a warning message "Object doesn't support this property or method" is displayed

If I disable the error handler then it takes me to one of these lines

Me.FolderImage.PictureData = Forms!subfrmSystemImages!SHImage1.PictureData


Perhapes I am going about this all wrong after all should I have been storing the route of each image in a table and calling them using an unbound image

And storing the image in a table will this give a administrater  with access to the form the ability to change the image with a button under each of the images. If so how best would this be achieved?

I have been trying to sort this out in order to ensure that the database remains light wieght and the forms quick to load.

Any ideas or solutions would be appreciated
0
MGardner
Asked:
MGardner
  • 6
  • 6
  • 5
  • +1
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
No sure what might be going on ... but have you seen this:

http://www.ammara.com/  DBPix ...

I can totally vouch for this program.  

It does all the work for you. Examples show how to add a simple 'control' panel to Load, Save, Zoom In/Out, Size To Fit and much more.  AND ... virtually eliminates BLOAT associated with storing images in an Access MDB.

Note. I have no connection with DBPix ... except I have used it many times ...

mx
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
<Perhapes I am going about this all wrong after all should I have been storing the route of each image in a table and calling them using an unbound image >

Generally speaking, yes ... you shouldn't be storing images in an Access database since this tend to bloat the db. You'd typically set the .Picture property:

Me.YourImageControl.Picture = "Full path to your picture"

If, however, you use an image many times throughout your db, you might consider building a form that contains ONLY that image, and then embed that form as a subform when needed ... this basically uses the form only once, and the subform embed won't cause bloat.

BTW: Access makes no distinction between a visible form and a hidden form, at least from a code standpoint ... doing this:

Forms("frmSomeForm").SomeValue

will work whether the frmSomeForm is hidden or visible ...

0
 
MGardnerAuthor Commented:
Hi

I understand the problem of the bloating which is why I used the image control and set it to link

I created a form showing all the images that would be used in the data base and as I pointed out depending on the user logging in they would get to see which image on the opening page.

I am realy just trying o make the Db as lightweight as possible while using images in this manner
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
"I understand the problem of the bloating which is why I used the image control and set it to link "

You should really check out DBPix ... seriously ... you will be AMAZED as to how it reduces bloat .... and has a very slick control interface.

mx
0
 
MGardnerAuthor Commented:
Hi I think that the DBpix looks good but at a price and I'm trying to avoid buying into solutions so that I can learn and work through some problems (with some help of course).
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Think of it like this:  Is $100 worth your time  ... when someone has figured it all out for you ?  What is your time worth?

mx
0
 
harfangCommented:
I'm with MGardner on this one. About once every two years, I'm tempted by some external add-on (the last two being a RTF control, and the Mozilla WebBrowser), but it's never worth it in the long run. You gain (a little) now and loose (a lot) later in maintenance.

It's like: why buy an expensive pair of shoes, if I can get a pair for 12.99? I always found that the cheap pair is more expensive in the long run.

Back to images.

I use three techniques for what you seem to need:

a) static hidden form with an image library

This is very similar to your scenario, but I make sure the form is opened first. Also, I don't insert the images using their path, but use copy-paste from Paint and then use Convert to image. This makes sense, as the "preview" of the image is a DIB anyway, so there is no need to store it twice.

> I get a warning message to say that the Db can't find the form with the images

Make sure that the form is loaded. For example:

    If SysCmd(acSysCmdGetObjectState, acForm, "subfrmSystemImages") Then
        ' form is loaded, proceed...

BTW: this is a strange name for a form: subfrmSystemImages. It makes it look like a subform, while it clearly needs to be a hidden main form... I'd use zsfrmSystemImages for that (system form prefix).

b) use a table with OLE bitmaps

This is the only form of OLE I use (and only in prototypes). The table can contains the images needed, and I display them in a subform, using link fields to display the correct image. This is quite fast, and it's easy to let the user update an image, even in an MDE database.

For a more robust approach, I replace OLE with BLOBS. Again, the images are stored in a table, but without the silly OLE overhead. However, you can no longer use a bound object frame to display them. It needs some coding.

c) use only external images

My favourite. You can however use techniques similar to HTML pages, by preloading the images you are likely to use in a form. This is especially meaningful if you use the images both within the application and without (html pages, external reports, etc.) A user can easily be instructed on how to replace the images.

Cheers!
(°v°)
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
<Think of it like this:  Is $100 worth your time  >

The distributable version is $350 ...
0
 
MGardnerAuthor Commented:
Hi Harfang

I understand about using a table to store the images and I have used the storage and retrieval of blobs but these are all based on one record one image and would be pretty heavy going setting up the coding. What I am trying to explore is the ability of storing multiple images on one form and a user being able to change the Image

I have created a table "tblSystemImages" with the following

lngImageID  - Indexed, Autonumber
ImageName - textbox for storing the name of the image  such as

BCImage1
BCImage2
BCImage3
GRImage1
GRImage2
GRImage3 etc.

and finally

memImagePhotoLink  - Memo to store the image link

I have placed a text box above each image

and tried to link the text box to the field in the table that would reference the image associated with it.

=tblSystemImages!ImageName="BCImage1"

but get Name#

I'm guessing that If I can get the reference ok I should be able to reference the unbound OLE object to it and retrieve the photolink associated with the name?

Can I do this in Access?
0
 
harfangCommented:
When you write

=tblSystemImages!ImageName="BCImage1"

You probably want some information from the table, corresponding to "BCImage1". That would be:

= DLookup("memImagePhotoLink", "tblSystemImages", "ImageName='BCImage1'")

Note that you probably don't need lngImageID. Simply use ImageName as key field.

You can do something similar in VB and then set the .Picture property of the OLE control to display the image from disk.

(°v°)
0
 
harfangCommented:
Note that this is drifting from your original question. Your idea does work as stated in the question, provided you make sure the form is in fact loaded first. The error messages you got proved that you were attempting to read from the form before it was loaded (or perhaps that you mixed up form and subform referenced).
(°v°)
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
"The distributable version is $350 ..."

About 2 billable hours :-)

mx
0
 
MGardnerAuthor Commented:
mx I can see where you see that there is merit in buying into something that has already been invented but I get great satisfaction and gain learning from working through problems and finding solutions to the things that I need for my database. A bit like when I was a kid I used to love buying a airfix kit and building a aircraft and painting it and certainly got great pride at my finished product, certainly more than if i bought it and ask someone else to build it. Besides, If I were to buy DBPix $350 I might then be tempted by Peters Software shrinker stretch more money for an extra licence, FMS emailer etc. to name but a few on the market. I'm sure I could rake up $1,000 on a finished database but in the meantime learnt nothing.

Harfang i managed to solve the warning message by placing the open form at the begining of the open event of my log in form so it opened before it did anything else. so now the folder opens with the correct image as I intended

This is loading the linked image from the hidden forms so now I have the table wish to give some control to an administrator of the database in chossing the images. So how would it be best to link the OLE to the image path in the table. as per your suggestion?

b) use a table with OLE bitmaps

This is the only form of OLE I use (and only in prototypes). The table can contains the images needed, and I display them in a subform, using link fields to display the correct image. This is quite fast, and it's easy to let the user update an image, even in an MDE database.

For a more robust approach, I replace OLE with BLOBS. Again, the images are stored in a table, but without the silly OLE overhead. However, you can no longer use a bound object frame to display them. It needs some coding.

Again would this display multiple images on one form/record instead of on image per record?
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
No problem. btw ... I also bought Peters Shrinker Stretcher ... excellent.  There is no-way I want to reinvent that code :-)

I was able to create a custom Zoom box which includes SS ... and also opens at a point very close to where the Zoom is called, ie next to a text box.

mx
0
 
harfangCommented:
MGardner,

I'm glad it now works for you.

As for the other solutions, they are different ways to attain the same final goal. So there wouldn't be several pictures available on a hidden form. The methods are completely different.

* Table with OLE

The image would be displayed in a subform. The link fields select the correct image for the selected department. This does not require any coding at all.

* Using BLOBs (or external files)

Your code would load the image into an image control. Again, no hidden form, just plain code to get the internal or external image and load it.

Cheers!
(°v°)
0
 
MGardnerAuthor Commented:
So basically i now have the form with the images on it and a text box above  the image and the following code retrieves the image path from the table. How can I now link the image control to the Image path in the text box?

= DLookup("memImagePhotoLink", "tblSystemImages", "ImageName='BCImage1'")

I tried putting this in the on current event on the form but it doesn't work.

Private Sub Form_Current()
    Me.OLEBCImage1.PictureData = BCImage1
End Sub
0
 
harfangCommented:
The property .PictureData expects a binary array (or a string) containing a stripped DIB image (basically the .PictureData of another image control, of a button, etc.). The property .Picture accepts a file name: it will open it (allowing several graphic formats) and display it.
(°v°)
0
 
MGardnerAuthor Commented:
Thank You Harfang

I have managed to make up a users form where all the images for the various database form headers and report headers are shown on the one form. Now a administrator has complete control on selecting the images they prefer by double clicking on any of the images. This then brings up a small pop up with the image and some controls to add, edit or delete the image and I'm very pleased with the result.

Mal
0
 
harfangCommented:
I'm glad to hear that. Success with your application!
(°v°)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 6
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now