Results 1 to 12 of 12
  1. #1
    Join Date
    Dec 2008
    Posts
    5

    Question Unanswered: Printing linked images from record

    Hi All,

    I'm struggling with a bit of vba coding for Access 2007. I have a form of records which have an image control on the form. Each record has a different linked image associated with the record. I wish to either print the image using a command button directly from Access or, by following the path of the image back to it's source, enable printing as though I had manually located the file in Windows Explorer, right clicked on it and left clicked Print.

    This is probably so simple that it probably seems a daft help request but I am quite a novice at vba and, whilst proud of what I have achieved, am now struggling.

    Many thanks in anticipation.

    Diggles1972.
    Last edited by diggles1972; 12-08-08 at 09:56.

  2. #2
    Join Date
    Dec 2008
    Posts
    5

    Hmmmm...

    Maybe this isn't such a simple solution as I first thought as nobody has been able to offer a solution. Can anybody tell me if it is even possible please or am I barking up the wrong tree?

    Many thanks.

    Diggles1972

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Sometimes you should wait longer than 2 hours 43 minutes before declaring this an impossibility!

    I'm sure someone with better Access skills will be along at some point to guide you.
    George
    Home | Blog

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you can assign the value of image at run time in a report and or form
    you need to handle the event when a image is missing or corrupted

    you need to set the path to to the image in two places
    once when an existing record is displayed (code goes in the forms on current event)
    again when the user edits the current record (code goes in one or more of the following
    the controls on change event (personally I wouldn't as this event fires every time a change is made to the path to the image)
    the control looses focus (and changes have been made to the control value.. you could examine the old value for the control and see if its changed

    you could set up a default image eg 'Image not found' and dispaly that

    one technique I've used in the past is to put a on error statement around the assigning of the image file

    eg
    if isnull(mycolumnname or len(mycolumname)=0 then ' no image set
    'assign a known value that exists
    myimagecontrol.Picture = "path\to\my\image\not\set\picture.jpg"
    'OR
    myimagecontrol.picture=none
    else
    myImagecontrol.Picture = "path\to\my\image\not\found\picture.jpg"
    On Error Resume Next
    myImagecontrol.Picture = mycolumname
    endif


    PS its only been three or four.. don't be so impatient
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Dec 2008
    Posts
    5
    <Off topic> My apologies to both of you. It wasn't impatience that drove me, more my uncertaintity and lack of confidence in my own ability in whether or not it was possible. I don't want to waste anybodies time with an unrealistic request. However, I consider myself chastised and will exhibit more patience in the future.

    <On topic> Many thanks Healdem for the error handler, I appreciate that and will certainly adapt and incorporate it as necessary. Unfortunately it doesn't help with getting a printed paper output in my hand from the image I already have in the record. I don't wish to print the whole record, just the image from a command button that I have placed on the form, entitled PrintThumb1 and a caption of "Print Thumb".

    Many thanks for any assistance you can offer and I'll have a ciggy instead of getting so paranoid, lol.

    Diggles1972

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so place some code behind the control button (double click the control, in ht eproperties select the events tab. select the buttons on click event, code option
    effectively its the same code, you 'just' need to put it behind the control.

    you can modify it so that if there is no picture url defined the button is disabled
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Dec 2008
    Posts
    5
    Hi Healdem,

    Thank you again for coming back to me. I think I've made myself a little unclear. The error handler is fine, I understand that and can see how that would be coded behind the control button, the issue I have is the code required to actually get the image to print in the first place. I know it might sound dense but I have explored all sorts of options including DoCmd.Printout and just cannot identify even a thread of a lead to the solution. So it's the code to print out the image from the record into paper format I need rather than the error handler (although that is appreciated too, thank you ).


    If it helps you understand what I am trying to achieve I've included a code extract.

    ---------Code Start--------

    Public Sub InsertThumb1_Click()

    Dim strFilter As String ', strFileName as string
    Dim lngFlags As Long

    strFilter = ahtAddFilterItem(strFilter, "Jpeg 3D Image (*.jpg, *.jpeg)", _
    "*.JPG;*.JPEG")
    strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")

    strFileName = ahtCommonFileOpenSave(InitialDir:="G:\Development\ ", _
    Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
    DialogTitle:="Locate 3D thumbnail file")

    'Check if a file is selected
    If Len(strFileName) > 0 Then ThumbImgPath.Value = strFileName


    If ThumbImgPath.Value <> "" Then
    Image29.Picture = ThumbImgPath.Value
    Else
    Image29.Picture = ""
    End If



    End Sub


    Private Sub PrintThumb1_Click()

    DoCmd.OpenView ThumbImgPath.Value, acViewNormal
    DoCmd.PrintOut

    End Sub

    ---------Code End---------

    I know I haven't placed your error handler in there yet but I would like to, with your permission, once I've obtained a paper printout of the image. The InsertThumb1 ()sub works fine and I'm happy with that but it's the PrintThumb1 () sub that has the problem.

    Many thanks.

    Diggles1972
    Last edited by diggles1972; 12-09-08 at 06:06.

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    So just the image and nothing else?

    Create a report which displays the image - set the image path at runtime just as you do on your form then printing becomes trivial
    George
    Home | Blog

  9. #9
    Join Date
    Dec 2008
    Posts
    5
    Thank you Georgev. Is that the only way I can do it or can I print straight from the form? The people who are going to use this database have next to no computing skills let alone database specific skills. And yes, just the image nothing else, that's correct

    Thank you so much for looking at this for me.

    Diggles1972.
    Last edited by diggles1972; 12-09-08 at 06:26.

  10. #10
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Create the report and then create an event that prints the report (you don't have to open it to print afaik) from your form.
    George
    Home | Blog

  11. #11
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you can assign the image at runtime.. all you need to do is supply the path to the image to the control
    so you store that in the db.
    you users supply that as part of the data capture.
    thats part of the reason why I suggest you have a couple of stock images as part of the data capture
    one is "image not supplied"
    the other "is image not found"
    you display image not supplied if the URL is empty
    you display image no found first, then attempt to set the image path, using the error handler, if it fails it the user sees image not found... otherwise they see the selected image
    Attached Thumbnails Attached Thumbnails imagenotfound.png   imagenotspecified.png  
    I'd rather be riding on the Tiger 800 or the Norton

  12. #12
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Maybe you do have to open it... But then add the code to the report open event instead!
    Code:
    Private Sub Report_Open(Cancel As Integer)
    
        'Set image
    
        DoCmd.PrintOut acPrintAll
        DoCmd.Close
    
    End Sub
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •