Reputation: 59
i have a form in access with one field (club_name), i have a picture object in this form. someplace in a folder i have some pictures (*.png) that each club's picture equal to records in my table.for example i have a record "FCB" and in that folder i have a picture "FCB.png". i myself code like this:
Private Sub Form_Current()
Image5.Picture = "C:\Users\Milad\Desktop\club imgs\" & Club_Name.Text & ".png"
End Sub
but it's not right.
please help?
Upvotes: 2
Views: 6463
Reputation: 91376
Do not refer to the text property of controls. It is only avaiable when the control has focus. If you must use a property, use value.
Me.Image5.Picture = "C:\Users\Milad\Desktop\club imgs\" & Me.Club_Name & ".png"
You can also check that it all works by using a "real" name:
Me.Image5.Picture = "C:\Users\Milad\Desktop\club imgs\FCB.png"
Re Comment
sPath = CurrentProject.Path & "\"
sBlank = "Blank.png" ''Your own default empty picture
If IsNull(Me.Club_Name) Then
sFile = sBlank
Else
''Does the file exist? Note: Use FilesystemObject
''instead if you are working network paths.
sFile = Dir(sPath & Me.Club_Name & ".png")
''Empty string ("")
If sFile = vbNullString Then
sFile = sBlank
End If
End If
Me.Image5.Picture = sPath & sFile
Upvotes: 1