Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    finding a file (xp)

    Ok
    I am working on a database where I want to put in a logo picture. Simple enough. so at work the link is C:minepologologo.jpg. I copied the whole thing home and placed it c:workpologologo.jpg I know the problem is the file paths are not the same. Is their any way of instead of giving it a absolute path you can tell it is in the sub folder logo under the folder the database is in like ..logologo.jpg so it doesn't matter where the main directory file folder is as long as the logo.jpg file is in the logo directory.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: finding a file (xp)

    Access stores the absolute path of the image file. So you should either create the same folder structure on your home PC as at work, or use code to change the path each time the database is opened.

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: finding a file (xp)

    My solution to this is to store just the relative path, and convert back to full path whenever I use it.

    So I have function that finds the location of the backend file (fngetlinkedpath) and when I insert an image I trim that off the field name.

    Me![Photofile] = Right(strFilename, Len(strFilename) - Len(strLinkedpath))

    Then to display the photo I add it back on again.
    Regards
    John



  4. #4
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: finding a file (xp)

    I am access the location of the logo threw a table [imagetable] field [Imagepath]

    then in the from I have

    Private Sub Form_Load()
    Me![ImageFrame].Picture = Me![ImagePath]

    is ther some way to have a database look at the path it is in right now (its absolute path) then do something like this
    Private Sub Form_Load()
    [pathname] = the command to find the relative path + the path to the logo (logologo.jpg)
    Me![ImageFrame].Picture = Me![Pathname]

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: finding a file (xp)

    You can use CurrentProject.Path to get the path of the database:
    <code>
    Dim strPath As String
    Dim strFile As String
    strPath = CurrentProject.Path
    If Not Right(strPath, 1) = "" Then
    strPath = strPath & ""
    End If
    strFile = strPath & "logologo.jpg"
    Me.ImageFrame.Picture = strFile</code>

  6. #6
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: finding a file (xp)

    I am trying to use this on the "on open" event of a report.... nothing happens.

  7. #7
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: finding a file (xp)

    The OnOpen event is too early. Try shifting your code to the OnFormat event of the section that will hold the image.
    Regards
    John



  8. #8
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: finding a file (xp)

    This worked great but the picture did not print.... any ideas.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: finding a file (xp)

    What do you mean by "this worked great"?

  10. #10
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: finding a file (xp)

    Are you saying that when you Preview the report the Picture is displayed, but if you then go on and Print it, the picture is not printed?

    If this is the case, I suspect that the code is running a second time and the second time it does not work.

    Do you have the whole of the code that Hans posted in the one event? or just some of it?
    Regards
    John



  11. #11
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: finding a file (xp)

    Are you saying that when you Preview the report the Picture is displayed, <font color=blue> Yes it is displayed </font color=blue>but if you then go on and Print it, the picture is not printed? <font color=blue> you got it </font color=blue>
    If this is the case, I suspect that the code is running a second time and the second time it does not work.<font color=blue> it is the only code on the report </font color=blue>

    Do you have the whole of the code that Hans posted in the one event? or just some of it?
    ------------------------------------------------------------------------<font color=blue>
    Option Compare Database
    Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)

    Dim strPath As String
    Dim strFile As String

    strPath = CurrentProject.Path
    If Not Right(strPath, 1) = "" Then
    strPath = strPath & ""
    End If
    strFile = strPath & "logologo.jpg"
    Me.ImageFrame.Picture = strFile
    End Sub
    </font color=blue>

  12. #12
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: finding a file (xp)

    I was talking about John's help.. Its worked great except for a little snag.

  13. #13
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: finding a file (xp)

    I just looked at an example of mine where I do something similar, and I found that I actually do the work in the OnOpen event like you first tried. So I don't know why it did not work for you there.

    Also tried it in the OnFormat event of the report header, and can't reproduce your problem there either.

    Two things to try:

    After this line Option Compare Database, add
    Option Explicit This force you to declare all variables, and so will alert you to typing errors in variable names.

    After strFile = strPath & "logologo.jpg" put in this on the next line

    msgbox strFile
    Regards
    John



  14. #14
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: finding a file (xp)

    The msgbox comes up twice..... but I can only fine it once in the code.....

  15. #15
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: finding a file (xp)

    The event occurs twice.
    Then when you print the report, it will occur again - twice more I expect.

    The important thing is whether it displays the correct filename and path each time.
    Regards
    John



Page 1 of 2 12 LastLast

Posting Permissions

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