-1

Client has asked me to create a self contained tool in MS Access, versions 2007 and 2016. It needs to be self contained because it will be copied to and from various laptops at various times. The tool may not create, delete, or modify any file except the accdb database itself. When the tool is in use, the user is unlikely to have network or internet access.

One of the criteria is the creation of new forms each time it is run. I realize that Access is meant to have all the forms and their controls already built before deployment, but client doesn't want that. I have solved that problem, creating x number of forms upon certain conditions, and creating 30-40 controls on each form based upon certain conditions, each with their own events, etc.

Now, how do I load his logo into a control on each form? Remember, the accdb must be self contained, so I can't count on the logo being in a certain directory or even on the machine in use, and I can't write it to the file system myself.

I can and have loaded the logo (jpeg) into one of my tables in an attachment field. It will be the only attachment in that field. It would be just as easy for it to be its own table, if that helps.

I can create attachment controls with VBA, but I don't know how to set the ControlSource to the FileData inside the attachment with VBA.

I also have had poor success attempting to embed the picture in an image control in a hidden form and setting the .picture property to the image name. It only seems to be working on my machine.

So, how do I display an attached jpeg on a newly created form?

CWilson
  • 425
  • 10
  • 28
  • 1
    If you already have the image saved within the database in an Attachment field then you should be able to save it as a "real" file in `%TEMP%` and then you'll know where it lives on the file system. From there you could do whatever you've previously done to embed it into your form(s) when the image file was in a known location. – Gord Thompson Jun 23 '16 at 23:06
  • @GordThompson Thank you. Perhaps this is the best option, unfortunately it is explicitly against what the client asked for. I am sorry I was unclear, but when the client says 'self-contained', he means that I should not be writing to or reading from he file system. The client has had bad luck previously with different tools that write to his file system. If what I asked for and what the client specified is impossible, then I will offer this as the work around, but the client will not be happy. – CWilson Jun 24 '16 at 04:51
  • I am now editing the question to make the phrase 'self contained' be a little more clear. I want anyone who attempts to help to understand that creating files, deleting files, or modifying any file but the accdb, is strictly forbidden by the client. Not really for technical reasons, but because a previous project that I was not involved in went awry, and damaged information that should never have been accessed. – CWilson Jun 24 '16 at 04:56
  • In my opinion your client's restriction is unreasonable. By the way, are they aware that when Access opens an .accdb file it creates at least two (2) of its own temporary files in `%TEMP%`? – Gord Thompson Jun 24 '16 at 13:00
  • @GordThompson It may be. He is not. And I am not going to enable 'view hidden files' or be the one to tell him. And I am certainly not going to try to explain the swap file or anything like it. On the other hand, from my understanding (PM background, not a programmer), this particular request ought to be possible, in this case. If the binary is there, in a readable format, there is software that can access that location, and that software can perform the desired action (all true in this case, right?), then there ought to be a command to do just that. Am I naive? – CWilson Jun 24 '16 at 14:23
  • "Possible?" Maybe. "Practical?" Unlikely. "... there ought to be a command ..." Unfortunately yes, that statement is a bit naïve. Access has been around for over 20 years and the particular feature you desire never got added, probably due to insufficient demand. – Gord Thompson Jun 24 '16 at 15:24

1 Answers1

-1

Just asked and answered in SO access-vba. Here's one solution. Saving Image as OLE Object, in Access

Many others on google and SO search

EDIT: You must read the whole question to see the author's answer

Answer:

So, what I ended up doing was following this https://support.microsoft.com/en-us/kb/210486

I use the readBLOB function to read the file and save it into the database. Then, when I run a report or open a form that has the picture, onload, I use the WriteBlob function to write the file to a temp folder and then use that path to populate an Image object.

Community
  • 1
  • 1
dbmitch
  • 5,361
  • 4
  • 24
  • 38
  • hmmm... I think maybe you accidentally linked the wrong question. That question has only one answer, and that answer doesn't actually address its question. The question is about importing a file into a database, and the answer is simply "don't do it" with two links. Since I have already "done it", that answer isn't really relevant. The links are interesting, of course, and one even does mention images, but neither address my question of how to display the image already located in the database. – CWilson Jun 24 '16 at 04:49
  • You must read the whole question to see the author's answer - he answers his own question with description of what he did - and includes a relevant link. Edited my answer in case you don't want to go back again – dbmitch Jun 24 '16 at 05:22
  • 1
    Thank you for explaining what you were thinking. I did see that the OP for that question edited his question to give what they thought was an acceptable answer inside the question. Unfortunately, that 'answer', while I sincerely hope it helped that individual, is not self contained. It is backward compatible to Access 97 at least, which is good, but in my stated case of 2007 and 2016, attachments would actually a more efficient way of doing that... again, if I could create delete and modify files. – CWilson Jun 24 '16 at 05:57