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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing Image Files via Text Box

Status
Not open for further replies.

TOTCOM11

Programmer
Aug 5, 2003
199
0
0
US
Hello,

I am trying to store image files in my database. I have a maximum of three images that I would like to be seen. This is a product database so some products will have as many as three images, and some may have as few as one. The query which is the control source for my form has three text fields (one for each picture) where the directory path for the images are stored. The text fields are Pic1, Pic2 and Pic3. The three object frames I am trying to link to are called PICTURE1, PICTURE2, and PICTURE3. Here is the code I am trying to use.

Code:
Private Sub Form_Current()

'Code to link pictures
Dim strPath1 As String
Dim strPath2 As String
Dim strPath3 As String

    On Error GoTo err_Current

    strPath1 = Me!Pic1
    strPath2 = Me!Pic2
    strPath3 = Me!Pic3

    ImgCtrl.PICTURE1 = strPath1
    ImgCtrl.PICTURE2 = strPath2
    ImgCtrl.PICTURE3 = strPath3

exit_Sub:
    Exit Sub
    
err_Current:
    MsgBox Err.Description
    Resume exit_Sub

End Sub

For some reason when I try switching between products I get an "invalid use of Null" error message and none of the pictures show up. Can anyone tell me what I am doing wrong?
 
Until you place a value in a field ie; (me!pic1 ) it is filled with a null value which is like no other. null + 1000 = null is an exmple. One way to get around a null is to use the nz( ) function which changes a text value to "" and a number value of null to zero which is manageable.

You could also do a test

if not isnull(me!pic1) then .... else .....


rollie
 
And I think you have to take a look at the LoadPicture method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
What do you mean by the LoadPicture method PHV? Also, when I try loading a record in the form that has all three pictures, I get a different error message. This error message reads, "Object Required".
 
Something like this:
Set ImgCtrl.Picture = LoadPicture(strPath)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I'm still getting a null error. Am I setting my "strpaths" correctly? I am trying to set StrPath1 to equal Pic1 which is located in a query. This query is the control source for the form.
 
Alright, I believe I have the null string thing fixed now. I just put Nz(Me.Pic1) etc... into my code and it's handled it very well. Now I am getting an "Object Required" error. Will a normal object frame work for this (assuming it is a bound object frame)?
 
In case you wanted to see, here is my updated code thus far:

Code:
Private Sub Form_Current()

'Code to link pictures
Dim strPath1 As String
Dim strPath2 As String
Dim strPath3 As String

    On Error GoTo err_Current

    strPath1 = Nz(Me!Pic1)
    strPath2 = Nz(Me!Pic2)
    strPath3 = Nz(Me!Pic3)

    Set ImgCtrl.PICTURE1 = LoadPicture(strPath1)
    Set ImgCtrl.PICTURE2 = LoadPicture(strPath2)
    Set ImgCtrl.PICTURE3 = LoadPicture(strPath3)

exit_Sub:
    Exit Sub
 
Alright,

I have ridded myself of all the error messages now, but I cannot get the pictures to display in my object frames. Here is the code I currently have:

Code:
Private Sub Form_Current()

'Code to link pictures
Dim strPath1 As String
Dim strPath2 As String
Dim strPath3 As String

    On Error GoTo err_Current

    strPath1 = Nz(Me!Pic1)
    strPath2 = Nz(Me!Pic2)
    strPath3 = Nz(Me!Pic3)

    Me.PICTURE1 = LoadPicture(strPath1)
    Me.PICTURE2 = LoadPicture(strPath2)
    Me.PICTURE3 = LoadPicture(strPath3)
'End Code to link pictures    

exit_Sub:
    Exit Sub
    
err_Current:
    MsgBox Err.Description
    Resume exit_Sub

End Sub

I looked up in VB help what LoadPicture does exactly and this is what I got:

Code:
The LoadPicture method returns an object of type Picture. You can assign this value to a variable of type Object by using the Set statement.

The Picture object is not a Microsoft Access object, but it is available to procedures in Microsoft Access.

Note   You can't use the LoadPicture method to set the Picture property of an image control. This method works with ActiveX controls only. To set the Picture property of an image control, simply assign to it a string specifying the file name and path of the desired graphic.

I tried removing the LoadPicture method, but unfortunately nothing changed. Any ideas of what I should do next?

Chris
 
Something just hit me....do I need to use an ActiveX control to make this work, or can I just use a standard Access object frame?
 
I also noticed that I am using jpegs. Does this create a problem for me?
 
I finally did it! Here's the code that fixed all my problems!

Code:
Private Sub Form_Current()

'Code to link pictures
Dim strPath1 As String
Dim strPath2 As String
Dim strPath3 As String

    On Error GoTo err_Current

    strPath1 = Nz(Me.Pic1)
    strPath2 = Nz(Me.Pic2)
    strPath3 = Nz(Me.Pic3)
    
    If IsNull(Me.Pic1) = False And IsNull(Me.Pic2) = True And IsNull(Me.Pic3) = True Then

        Me.Image1A.Visible = True
        Me.Image1B.Visible = False
        Me.Image1C.Visible = False
        Me.Image2A.Visible = False
        Me.Image2B.Visible = False
        Me.Image3.Visible = False

        Me.Image1A.PICTURE = strPath1

    ElseIf IsNull(Me.Pic1) = False And IsNull(Me.Pic2) = False And IsNull(Me.Pic3) = True Then

        Me.Image1A.Visible = False
        Me.Image1B.Visible = True
        Me.Image1C.Visible = False
        Me.Image2A.Visible = True
        Me.Image2B.Visible = False
        Me.Image3.Visible = False

        Me.Image1B.PICTURE = strPath1
        Me.Image2A.PICTURE = strPath2

    ElseIf IsNull(Me.Pic1) = False And IsNull(Me.Pic2) = False And IsNull(Me.Pic3) = False Then

        Me.Image1A.Visible = False
        Me.Image1B.Visible = False
        Me.Image1C.Visible = True
        Me.Image2A.Visible = False
        Me.Image2B.Visible = True
        Me.Image3.Visible = True

        Me.Image1C.PICTURE = strPath1
        Me.Image2B.PICTURE = strPath2
        Me.Image3.PICTURE = strPath3
        
    ElseIf IsNull(Me.Pic1) = True And IsNull(Me.Pic2) = True And IsNull(Me.Pic3) = True Then

        Me.Image1A.Visible = False
        Me.Image1B.Visible = False
        Me.Image1C.Visible = False
        Me.Image2A.Visible = False
        Me.Image2B.Visible = False
        Me.Image3.Visible = False

    End If
    'End Code to link pictures

exit_Sub:
    Exit Sub
    
err_Current:
    MsgBox Err.Description
    Resume exit_Sub

End Sub

Thanks for everyone's help!

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top