Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot add Image to Command Button?

Status
Not open for further replies.

PrimoSteve

Technical User
Aug 11, 2021
25
IE

I have a form that displays a Gridview-like with 20 button controls (displays different products with the name and image)
I have several other button controls which represents Categories and when click calls this function "Call Display_Products"

Function Display Products

w = 0
q = 0
For z = 1 To 20


Me.Products = Me.Products.ItemData(z - 1)
Me.Controls("ProductName" & z).Caption = Nz(Me.Products.Column(1), "")
Me.Controls("ProductName" & z).Picture = Nz(Me.Products.Column(2), "")


If IsNull(Me.Products.ItemData(z - 1)) Then
Me.Controls("ProductID" & z).Value = Null
Me.Controls("ProductName" & z).Visible = False
Else
Me.Controls("ProductName" & z).Visible = True
q = z
Me.Controls("ProductID" & z).Value = Me.Products.Column(0)
w = w + 1
End If


This works fine in my own personal pc just as long as the images are stored in My documents.
Otherwise, I get a runtime error 2214 POS doesn't support the format of the file 'Buuter.gif,' or file is too large. Try converting to BMP format.
I've installed this in my work pc but I'm getting the same runtime errors whether the images are stored in My Documents or elsewhere
Note: I've tried using BMP, PNG, JPGS and even tried changing the ProductImage field to short text but still same thing

ProductID Autonumber
CategoryID Number
ProductName ShortText
ProductImage Attachment
Description ShortText

So I've decided to use the image control instead of the button control but can't seem to get my head around calling the image control instead of the button control. I'm still getting the same runtime error

Me.Controls("ProductName" & z).Picture = Nz(Me.Products.Column(2), "")
 
I would comment out almost everything and hardcode the control name and image name. This might determine more troubleshooting based on success or failure.

What are the typical values in Column(2)?

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Hi Duane,

Typical Values in Column(2) is an Attachment like a BMP, GIG, PNG , This is the Data Type

TABLE Products
ProductID - Autonumber
CategoryID Number - Number
ProductName -ShortText
ProductImage - Attachment
Description -ShortText

The product name and image on the button control show's up no problem once the image is stored in Documents but if the images are stored elsewhere I get a runtime error.
This is working fine in my own personal pc (Windows 10 Pro) but installed in my work pc (Windows 10) it's throwing out a runtime error regardless where if images stored in Documents

ProductName - ShortText Me.Controls("ProductName" & z).Caption = Nz(Me.Products.Column(1), "")
ProductImage - Attachment [highlight #FCE94F] Me.Controls("ProductName" & z).Picture = Nz(Me.Products.Column(2), "")[/highlight]

I'm guessing it has something to do with Access and Windows linking the attached photos in the table.
So I thought I would try and use an Image Control instead of a Button Control but I'm not sure how to code or reference an Image C
GRIDVIEW_fe1n3a.png
ontrol
 
I haven't ever used the attachment type field and can't see spending the time to attempt to duplicate and test. I have always used a short text field to store the location/name of the image file. I think the reason your code works on your PC is that the path to "Your Documents" is stored in the attachment field. In a different environment, "Your Documents" won't be the same fully qualified folder.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
It's not clear for me, where you store the images: in external folder or as attachment?

If in folder, you need a full path stored, if using image control, set PictureType to 1 (linked picture) and Picture to stored path.

If in attachment - only short file name is stored in table, you have attachment control to display data.

You may find this database useful to display attachments (in subform).

combo
 
Ok, so I have replaced the Button Control with an Image Control it's working now.
Except on the Button Control I was able to add both a caption from a field on the table called ProductName
along with the Image from another field on the table called ProductImage,

I'm getting a Run-time error '438':
Object doesn't support this property or method on the 1st line below

Me.Controls("ProductName" & z).Caption = Nz(Me.Products.Column(1), "")
Me.Controls("ProductName" & z).Picture = Nz(Me.Products.Column(2), "")

Not able to add a caption on the Image Control and instead, inserted an unbound textbox next to the Image Contol
to substitute for the caption. Could someone advise how to code or the correct approach to showing the ProductName with the ?

Thanks for the help again,


 
Function DisplayProducts()

Dim w As Integer
Dim q As Integer
Dim z As Integer

w = 0
q = 0
For z = 1 To 20

Me.Products = Me.Products.ItemData(z - 1)

' Caption for the TextBox control
Me.Controls("ProductName" & z).Value = Nz(Me.Products.Column(1), "")

' Image
If Not IsNull(Me.Products.Column(2)) Then
Me.Controls("ProductImage" & z).Picture = Nz(Me.Products.Column(2), "")
Else
Me.Controls("ProductImage" & z).Picture = ""
End If

If IsNull(Me.Products.ItemData(z - 1)) Then
Me.Controls("ProductID" & z).Value = Null
Me.Controls("ProductName" & z).Visible = False
Me.Controls("ProductImage" & z).Visible = False
Else
Me.Controls("ProductName" & z).Visible = True
Me.Controls("ProductImage" & z).Visible = True
q = z
Me.Controls("ProductID" & z).Value = Me.Products.Column(0)
w = w + 1
End If
Next z

End Function

C.
 
Hi C,

I've also tried coding below replacing it with Value but I was getting a Run-time error '438':
Object doesn't support this property or method with below line

' Caption for the TextBox control
Me.Controls("ProductName" & z).Value = Nz(Me.Products.Column(1), "")

Thanks
 
Yeah, that 438 error is a bit vague.

To me, it's saying either the control name doesn't exist or the Me.Products.Column(1) reference is not correct.

Try this:
1) Ensure that the controls named ProductName1 thru ProductName20 exist on the form.
2) Verify the Me.Products.Column(1) supports the Column method. I think only Combo or List Box might have that?

Also, step through and capture the error using the below and post back..


On Error Resume Next
Me.Controls(ctrlName).Value = Nz(Me.Products.Column(1), "")
If Err.Number <> 0 Then
MsgBox "Error " & Err.Number & ": " & Err.Description
Err.Clear
End If
On Error GoTo 0
 
After playing around decided to stay with the Button Control instead of the Image Control.
Must have been a bug or something I just copied and paste the table again and added new data. Seems to be working just fine now both in my personal and work pc.

Thanks all,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top