Access 2016 linked picture path lost after closing and reopening the database - vba

1 main form, containing 2 subforms:
first subform, datasheet view: list of employees; second subform, single form view: contact details and photo.
frmContactDetails has a image (inserted using design>controls>image), which contolsource is linked to the employee photo path.
frmEmployee, On Current event: requery frmContactDetails.
I linked a blank photo in image.picture property.
Everything works well, I can select any employee and see all détails and photo updating according to the current record. I can do a compact and repair, reopen the main form, and it is still working.
Problem: When I close and reopen the database, photos are not updating anymore. In design view, image.picture property still shows the complete blank photo path in the field, but when I clic to the 3 dots button, it does not reach the folder conatining this photo. I need to set again the correct path, save and reopen the form to make it work again.
I've been trying to find a solution for hours without success.
frmEmployee record source:
SELECT tblEmployee.Email, tblEmployee.EmployeeName FROM tblEmployee;
frmEmployee OnCurrent event:
Private Sub Form_Current()
Me.Parent.txtEmployeeEmail.Value = Me.Email
Me.Parent.frmContactDetail.Requery
End Sub
frmContactDetails record source:
SELECT tblPhotos.Email, tblPhotos.PhotoName
FROM tblPhotos
WHERE (((tblPhotos.Email)=[Forms]![frmMain]![txtEmployeeEmail]));
frmContactDetails image: control source: PhotoName, picture type: Linked, Size Mode: clip, Picture property:
C:\Users\UserName\Desktop\test\BlankImage.bmp
Do you have an idea on what could be wrong?
Additional information:
All pictures are in .png format (except the BlankImage.bmp). I found a piece of code to load .png images in my custom ribbon and it works well. Pictures are stored in a subfolder of temp folder. I think this piece of code uses API and it is too complex for me to understand: I tried to use the same function to load images into the form without success. In tblEmployee, there is an attachment with .png photo. At first, I tried to link the Image control to this attachment, but it does not display photos. Then I copied images Inside a folder of the temp folder, and used the .Picture property to display photo Inside the image control. I added a Field to tbl Employee with PhotoName. A textbox in the form is linked to this field, and then I recreate the full path using Environ("temp")\photofolder[PhotoName].png. If there is no path in .Picture (in design view) it is set to (none) and image control do not refresh. I give the path to BlankPhoto in design view, and then all updates correctly when I use the form. The problem is if I close Access and re-open it, BlankPhoto path is still visible in .Picture but when I click on the three dots button the file picker starts in Document folder (the path is lost), and photos do not update correctly.
What would be the correct way to go?

Related

ACCESS VBA Picture saved as OLE OJECT used as Picture property for custom command bar

I have some custom popup menus in my app and i am tired of using the .FaceID property just to set some "not so relevant" images form my commands. What i want to do is to get some pictures saved in a local table OLE-OBJECT field and display those instead of the MS pictures.
The controls of commandbar object have .Picture and .Mask properties which work just fine if i load a file from the hdd into a IPictureDisp object using stdole.LoadPicture, but i don't want to have hundres of small files in my app folder.
So, my question is: is there a way i can get the picture saved in the local table to become a IPictDisp. I can get it's byte array just fine, but i found no way of converting that into something that the Commandbar button can recognize.
Thank you for any help.

PictureBox Missed In the .exe VB.net

I have A pictureBox in a form
I have declared a Picture box called Then
Field.Image = Image.FromFile("C:\Users\ABK\Desktop\Othello\field.png")
Field.Size = New System.Drawing.Size(483, 610)
Then I added the picbox to the form but when i copy the exr into another computer I don't see the picture
when I copy the exe into another computer I cannot see the picture
how can I include it in the exe file
Please try to keep the answers as simple as possible and demonstrate with examples
click on your form.
the properties tab should be on the bottom right
find image or background image and click on it
click the ... on the right side.
image as example of instructions above
a menu should show up.
Click import then select the file you want saved,
then press open it should go back to the menu,
select (none) to set your form image back to normal,
image as example of instructions above
then press ok,
go back to your code and change
Field.Image = Image.FromFile("C:\Users\ABK\Desktop\Othello\field.png")
to Field.Image = My.Resources.field
This should keep the image when you give it to your friend

MS Access 2007 add logo to all forms

I am wanting to add a logo to all my forms/reports etc. I want to either store the image once in the database, even in the front end is okay, or I want to access a picture on the network/local computer. I really don't care. I can store a location in a table, and use a dlookup call as the control source in a picture control, and it works, but there is a noticeable delay from when the form opens and when the picture actually appears. If I paste the picture in to every place, it works great! But if I want to change the logo, I must open all my forms/reports and change every single one.... there has to be a faster way to change out my logo pictures and still get them to load instantaneously. Can you help?
You could use vba perhaps. Create a global variable in a module to link to a file location. You could then use an image control on each form and set the source to the file location stored in your variable on the open event.. That way you would only ever change the value of the global.
Your code might look like this in each form:-
Private Sub Form_Open(Cancel As Integer)
Image0.Picture = yourGlobalFileLocationVariable
End Sub

Image location (code) of PictureBox control

I'm inexperienced with windows forms (vb.net), and I have a rather silly question.
I'm opening an old project of someone elses, and there's a PictureBox control on the form. The PictureBox has a photo, and I'm trying to find the location of the photo on the computer but can't find it.
In ASPX, I can just look at the code behind and find out where the tags are pointing to (for the photo).
Is there a way to do that for vb.net?
Update:
The only code that exists for my object, with the image property is this:
Me.pbTotal.Image = CType(resources.GetObject("pbTotal.Image"), System.Drawing.Image).
You can rightclick the picturebox -> Properties-> and there should be an image field with the informations you search
If its not set in the properties window which can be viewed by right clicking on the picture box it will be set in code using the image property.
The PictureBox control gives you two options for setting the image that is displayed on it. You can use the ImageLocation property or the Image property to perform the same task.
If you set the ImageLocation to the file name or url of a valid image/picture, image gets displayed and you can access it via the Image property as well. If you should use the Image property to set the image displayed, there will be no way to know the physical location of the image being displayed if you did not know it beforehand.
From the code you've pasted in your question, there no way way retrieve the path/url to the image file. To further complicate matters, the image is being loaded from your project's resources so any attempt to resolve the path/url would have to first go through the project resources before locating the original file and even if this is possible, for all practical purposes it is too cumbersome.
In short, if you'd like to get the path/url of the image loaded in the PictureBox at some point later, use the ImageLocation property instead of the Image property to set the image to be displayed.
Ok, I just found the true answer. Yes it in a resource file, but not for the project itself. I didn't know that forms themselves have resource files (.resx) as well.
In visual studio 2010 (not sure about the others), the .resx file is hidden. If you click the option to "Show All Files" in the solution explorer tool bar, you'll then see that the form can be drilled down. There in the .resx file, I was able to find my image.

vb.net add text to form without interaction

I have a winform project which lists all the files in a specified folder. It allows the user to select a new destination for each file, and when the user has chosen the destinations for all files that he would like to be moved, it moves the files, one by one.
My next step is, I need to display a confirm form when the files are being moved, and add each file's name and destination to the confirm form as it is being moved.
My question is:
How can I add more text to the confirm form's controls after I already loaded it (using confirm.showdialog() from my other form, without any user interaction? I imagine that I need to do it from the original form, because it needs to display each one when it starts to move that file, but I'm open to any suggestions:)
TIA
Both above answers are good.
If I understand correctly, your main form will allow one to select multiple files, then select their destination and launch the move process. If that's what you need, I would simply do the following:
Create a new form that would report the process to the user, without requiring any interaction, but just to inform the user what file is being moved;
Create an instance of a BackgroundWorker object, and call the file-move method from the BackgroundWorker.DoWork() method (within your main form);
Flag your BackgroundWorker to report progress, then call the BackgroundWorker.ReportProgress() event handler from within your move-file method;
Use the previously created list of file names to get its name and report it to your file-move dialog form while the file is being changed. A simple DataBinding over a Label should do the trick while you'll move your CurrencyManager to the next item within the list, or you could simpler use the list indexer to get the filename at a particular index;
When the user launches the move process, get your filenames and and count them, then set your ProgressBar Maximum value to the number of files you have.
The BackgroundWorker.ReportProgress() method takes an integer value as its argument, then, with your ProgressChanged() event handler, you will be able to display the name of the file being copied to your window by getting the filename at the index location, index given by your ReportProgress() method.
This will allow you to use the performance of a supplemental thread, without "freezing" your main thread from which your form has been created, then you will be able to simultaneously perform your file move, and display the filename to the progress-form, while illustrating to your user visually what the progress is about through your ProgressBar control, and displaying the filename as required.
Does this help?
Wouldn't it be simpler to make another form instead of using preset dialogs?
that way you can just have a textbox that you populate and refresh
You could do put all of the code to show the moving of the files inside the confirm dialog window.
But to give a more complete solution could you tell me how you are gathering the file moving information.
A Good solution would be to just pass in the list of the files to be moved and then perform the moving function in the dialog.