Results 1 to 4 of 4
  1. #1
    an1bone is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    9

    Opening images or documents in a form by double clicking

    Hello,



    I am working with images (JPEGs) and documents which vary depending on what record you are looking at. I have the file locations of the images/documents saved in the field of my table. Right now, I have the JPEG image appearing on the form when the specific record is specified. (I only have one image or document for each record.) I added an image to the form and set the image Control Source to the field with the image file location. My problem is that I want to be able to double click on the image to open it in a separate window (so that it can be zoomed in to read small text). Is there a way to do this??

    Thank you much!

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

    usage:
    OpenNativeApp "c:\folder\file.JPG" , will open the doc in your PC's default app for jpgs
    and
    OpenNativeApp "c:\folder\file.pdf" , will open it in acrobat

    so you would use on the DOUBLE_CLICK event:
    Code:
    sub img_double_clic()
      OpenNativeApp txtBoxPath
    end sub
    'depending what is in the text box, it will open in its own app.

    Code:
    'Attribute VB_Name = "modNativeApp"
    'Option Compare Database
    Option Explicit
    
    
    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
    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

  3. #3
    an1bone is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    9
    @ranman256 :

    Can you go more in depth with where/how you use this code? I am still fairly new with VB. Can this code be pasted into the Events of an Image control in the form, or do I have to put it into the module? I want a preview of the image to show up on the form, and then open the file by double clicking on the image if that's possible. Thank you!

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    the bottom box code, goes into a module.

    the form with the image, in the dbl-click event of that object put (or whatever txtBoxPath is called on your form.)
    OpenNativeApp txtBoxPath

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

Similar Threads

  1. Replies: 4
    Last Post: 09-02-2014, 03:53 PM
  2. Replies: 6
    Last Post: 04-26-2013, 10:07 AM
  3. Replies: 2
    Last Post: 02-13-2013, 04:14 PM
  4. adding images & documents to database
    By ksosnick in forum Database Design
    Replies: 2
    Last Post: 10-26-2011, 01:48 PM
  5. Opening another form by double click
    By chrisjack001 in forum Access
    Replies: 1
    Last Post: 10-13-2010, 02:19 PM

Tags for this Thread

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