Image on Load event (1 Viewer)

mba_110

Registered User.
Local time
Yesterday, 18:21
Joined
Jan 20, 2015
Messages
280
Hi

I am trying to load an image on form with form load event directly in event procedure, i have image frame on form and it will load the image once form is loaded or open.

Also i have more buttons and option on form that will change image upon selection individually, but in first on form load i need a different image.

Their is a way around to make table and reference the path in event procedure but i dont want to create a table just for images, so i decided to call it directly from events.

I try making it but not able to achieve the result

Code:
Private Sub Form_Load()
Dim image As ObjectFrame
Dim Location As String
image = Me.ImageFrame
Location = "Z:\Access Database\Financial Accounting System\Images & Icons\Create account.jpeg"
Me.ImageFrame = Location

End Sub

its giving me a error object variable with block variable not set.
 

bastanu

AWF VIP
Local time
Yesterday, 18:21
Joined
Apr 13, 2010
Messages
1,402
Try to use the picture property of the image control:

Me.ImageFrame.Picture=Location

Cheers,
Vlad
 

June7

AWF VIP
Local time
Yesterday, 17:21
Joined
Mar 9, 2014
Messages
5,465
If this is an Image control, I prefer to set ControlSource property. I've never used Picture property. It was required before Access 2007.
Code:
Private Sub Form_Load()
Me.ImageFrame.Properties("ControlSource") = "='Z:\Access Database\Financial Accounting System\Images & Icons\Create account.jpeg'"
End Sub
 

mba_110

Registered User.
Local time
Yesterday, 18:21
Joined
Jan 20, 2015
Messages
280
It not working in both ways, just nothing is pop up in picture frame on form load and also no error message.

frame stay blank.
 

June7

AWF VIP
Local time
Yesterday, 17:21
Joined
Mar 9, 2014
Messages
5,465
My suggested code works for me. If you want to provide db for analysis, follow instructions at bottom of my post.
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:21
Joined
Sep 21, 2011
Messages
14,231
When you select a picture in design mode Access (at least in 2007) sets the Picture property to the path of your picture.

I've just added a image control and set it to a picture.
Then used
Code:
Private Sub Form_Load()
Me.LblInvoice.Caption = ""
Me.imgPicture.Picture = "C:\Users\Paul\Pictures\Cozumel Feb 16\img_2333.jpg"
End Sub

to change it successfully
 

mba_110

Registered User.
Local time
Yesterday, 18:21
Joined
Jan 20, 2015
Messages
280
I dont have this part of argument in my code above.

Code:
Me.LblInvoice.Caption = ""

Microsoft access cant open the file "Z:\......"

attached the form my version is 2010
 

Attachments

  • Test1.zip
    118.3 KB · Views: 55

Gasman

Enthusiastic Amateur
Local time
Today, 02:21
Joined
Sep 21, 2011
Messages
14,231
I dont have this part of argument in my code above.

Code:
Me.LblInvoice.Caption = ""

I just amended an existing form in my test db. :banghead:
Remove that line. I just copied and pasted the whole snippet.

I'd expect you to recognise a control that is not relevant to you.?

I don't have a file at Z:\ so I would not use that as a path in my code.?

Microsoft access cant open the file "Z:\......"

attached the form my version is 2010

That tells me that the path is incorrect.
 

isladogs

MVP / VIP
Local time
Today, 02:21
Joined
Jan 14, 2017
Messages
18,209
I normally use Me.imgPicture.Picture in VBA
The supplied code works for me (obviously with my own image path)

As a check, I've tried all the following:
1. Setting the path in the Picture property of the property sheet ...using the full path with no quotes
2. Setting the path in the ControlSource property of the property sheet ...using ="full path here"
3. Using Me.imgPicture.Picture in VBA
4. Using Me.imgPicture.Properties("ControlSource") in VBA
All 4 methods work for me
 
Last edited:

June7

AWF VIP
Local time
Yesterday, 17:21
Joined
Mar 9, 2014
Messages
5,465
The path in your code is not Z drive.

The code works with my pathing.
 

Users who are viewing this thread

Top Bottom