Results 1 to 7 of 7
  1. #1
    Khayot is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2021
    Posts
    3

    Question Visibility of pictures

    Hello! I am new in Access and I faced a problem with displaying of the picture in my Datasheet form. I have made a hyperlink there to my another form where I have pictures which shows upon a certain condition. Here is a code:



    IIf([pl]>0;"C:\Users\Admin\Desktop\PL.png";Null)

    It works perfectly when I open a form manually, but when I open it through clicking a link in my DS form, these images do not display.

    By the way, to these pictures I have corresponding text boxes, which also show by a similar condition - here is a code:
    =IIf([PL]>0;[PL];"")

    And they display well, but pictures do not. Can you help me with that?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    Paste this code into a module, and it will open ANY file in its native application.
    In a form put the field and a button to open it.


    if the file is a picture, will open it in the app for photos
    if the file is myFile.pdf, will open it in acrobat
    if its just a file path, it will open in file explorer.
    etc..


    usage:


    Code:
    sub btnOpenFile_click()
      OpenNativeApp ME.txtBox
    end sub



    paste this code into a module
    Code:
    'Attribute VB_Name = "modNativeApp"
    'Option Compare Database
    Option Explicit
    
    
    #If VBA7 Then
      Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As LongPtr, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As LongPtr
      Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As LongPtr
    #Else
      Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
      Private Declare Function GetDesktopWindow Lib "user32" () As Long
    #End If
    
    
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    
    
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    
    
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    
    
    
    
    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long
    
    
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function

  3. #3
    Khayot is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2021
    Posts
    3
    Thanks for answer, I am like REALLY new in Access haha so maybe I did not understand you correctly, but it is not the thing I want
    I mean it the form there are some images and they just need to be displayed on it, without opening them in any application. Like here is how it should look:
    https://ibb.co/ZfsQWys

    But these tiny icons in the very bottom of the list are not displayed when I open form through clicking a link on them in a DS form

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Post 3 was moderated, I'm posting to trigger email notifications. I also deleted the duplicate post.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,776
    Impossible to say what's wrong based on your post, especially when you say that it works when opened one way but not another. Perhaps it involves how you're related a subform to a main form, but if there is no subform then what? I suggest you copy your db, compact and zip it and post it here for analysis.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111
    So the datasheet does not display the picture but from there you open a "single form" form with the picture control? How do you open the form? Do you have the [PL] field on this second form? If PL =2 do you want to open C:\Users\Admin\Desktop\PL.png or C:\Users\Admin\Desktop\2.png ? If the later you will need to use something like this: IIf([pl]>0;"C:\Users\Admin\Desktop" & [PL] & ".png";Null)

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    Forum post drops last \ character in unformatted code.
    Code:
    =IIf([pl]>0;"C:\Users\Admin\Desktop\" & [PL] & ".png";Null)
    But why would your non-concatenated expression show correct images at all? If you still need help, also suggest you provide db for analysis. Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 11-17-2019, 06:35 PM
  2. Visibility
    By Perfac in forum Forms
    Replies: 14
    Last Post: 08-25-2018, 01:49 AM
  3. Label Visibility
    By joecamel9166 in forum Reports
    Replies: 3
    Last Post: 05-03-2016, 05:24 PM
  4. Field Visibility
    By cbrsix in forum Programming
    Replies: 3
    Last Post: 06-27-2012, 03:52 PM
  5. subform visibility
    By nichmeg in forum Forms
    Replies: 9
    Last Post: 11-04-2011, 12:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums