How to have an empty image if there is no filepath stored for it


G

gklcity

Dear All,

I have a table with attributes id and imagepath (the path to an image file that is linked to the database). I also have a form with a textbox and a bound image frame, but only the textbox is bound to the imagepath attribute.

I want to write code so that the imagepath goes into the textbox and then the image shows up in the frame. I use the onCurrent event for the form and my code is shown below:

Private Sub Form_Current()
Dim txtImage As String
Const txtFilePath As String = "C:\Users\Admin\Desktop\"
If (IsNull(Me.ImagePath)) Then
txtImage = ""
Else
txtImage = Me.ImagePath
End If
If Not (txtImage = "") Then
MsgBox txtImage
Me!oleImage.Enabled = True
Me!oleImage.Locked = False
With Me.oleImage
.Class = "Paint.Picture"
.OLETypeAllowed = acOLEEither
.SourceDoc = txtFilePath & txtImage
.Action = acOLECreateLink
End With
MsgBox txtImage
Else
'Me.oleImage.Action = acOLEDelete
Me.oleImage.SourceDoc = vbNullString
Me.oleImage.Action = acOLECreateLink
End If
End Sub

It works as long as you have images in the database, but I would like the frame to show nothing when I navigate to a new record or a record that has no image. I tried to use acOLEDelete as the action but it is telling me I can only use that for embedded objects and I have linked objects.

Can I do this without using the image control and sticking with the bound object frame (if you bind it to another database that stores embedded bmp pictures it works fine, so there should be a way)?

Regards,
George
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top