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!

Loading Images in a Report Using Text Fields

Status
Not open for further replies.

TOTCOM11

Programmer
Aug 5, 2003
199
US
I have a product database that I have just successfully figured out how to link picture locations which are stored in text fields to image controls in a form. Now I am trying to do the same thing only in a report. If you are interested in how I came to my resolution for my form you can go to this site:

The text fields I am trying to link to are in text fields in a query, which is the control source for the report. The text fields are called Pic1, Pic2, and Pic3. If you notice in my code I have six image controls. The reason I have six controls for 3 pictures has to do with the positioning of the pictures. Not all products will have 3 pictures, so I have to space the pictures out accordingly. When I currently try opening the report, Access cannot find Pic1 (and I'm assuming Pic2 and Pic3), which leads me to the option of debugging. How do I link my Pic directories to my image controls so that they will open properly?

Code:
Private Sub Report_Open(Cancel As Integer)

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

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

'    Me.Image1A.PICTURE = strPath1
'    Me.Image1B.PICTURE = strPath1
'    Me.Image1C.PICTURE = strPath1
'    Me.Image2A.PICTURE = strPath2
'    Me.Image2B.PICTURE = strPath2
'    Me.Image3.PICTURE = strPath3

'        Me.Image1A.Visible = True
'        Me.Image1B.Visible = True
'        Me.Image1C.Visible = True
'        Me.Image2A.Visible = True
'        Me.Image2B.Visible = True
'        Me.Image3.Visible = True
    
    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

End Sub
 
With reports, you must have a control bound to Pic1, Pic2, and Pic3. The controls can be invisible. I would add three text boxes "txtPic1",... and then change your code to reference the text box names rather than the field names.

Also, I never use Nz() without specifying the second arguement:
Code:
    strPath1 = Nz(Me.Pic1,"None Available")
    strPath2 = Nz(Me.Pic2,"None Available")
    strPath3 = Nz(Me.Pic3,"None Available")


Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Just curious, why don't you use Nz() without using a second argument? It just defaults to "" if you don't do anything.
 
I now got a run time error:

You entered an expression that has no value.

What am I doing wrong now? I changed my Nz() so that it looks like yours.
 
I prefer to be explicit in my code. I think it's just good practice. Your use of "str" helps a programmer understand that Pic1 is text but sometimes it isn't clear whether the value is text or numeric.

It's all a matter of personal preference if you don't have multiple people maintaining the same code.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Change your code to explicitly set the if null:
Code:
    strPath1 = Nz(Me.Pic1,"")
    strPath2 = Nz(Me.Pic2,"")
    strPath3 = Nz(Me.Pic3,"")
or
    strPath1 = Me.Pic1 & ""
    strPath2 = Me.Pic2 & ""
    strPath3 = Me.Pic3 & ""




Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Alright, I tried both suggestions and I'm still getting that same error? Any thoughts?
 
Did you add controls to the appropriate section of your report that are bound to the Pic fields? What are the control names? What is your code? Which line(s) of code cause the error?

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top