Results 1 to 5 of 5
  1. #1
    DDP is offline Novice
    Windows 11 Access 2016
    Join Date
    Jan 2025
    Posts
    2

    Attachment Problem


    Hi,

    I am building a database for customer orders and on the form along with what the customer bought I have an empty image box that you double click which opens an attachment dialog where you click on add and you then find the picture you want and click ok to add it to the form and it worked fine initially but now when you double click the image box the attachment dialog appears but the all the buttons except cancel are greyed out.

    Can anyone help

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,571
    Firstly, it is not recommended to store attachments in the DB, it bloats the DB quickly.
    No idea to be honest, as I never use them for the above reason.

    Upload your DB so someone can try it out.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Instead of storing the picture in the db, (like Welshgasman said), store the path of the image, then open it using the function below.
    OpenNativeApp will open any file in its native application : .docx will open in Word, .jpg will open in the default paint app.

    usage using a listbox holding the path of the images

    OpenNativeApp lstBox


    Code:
    Option Compare Database
    Option Explicit
    
    
    #If Win64 Then
      'Declare PtrSafe Sub...
        Declare PtrSafe 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
        Declare PtrSafe Function GetDesktopWindow Lib "user32" () As Long
    #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

  4. #4
    jojowhite's Avatar
    jojowhite is online now Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    437
    Quote Originally Posted by DDP View Post
    Hi,

    I am building a database for customer orders and on the form along with what the customer bought I have an empty image box that you double click which opens an attachment dialog where you click on add and you then find the picture you want and click ok to add it to the form and it worked fine initially but now when you double click the image box the attachment dialog appears but the all the buttons except cancel are greyed out.

    Can anyone help
    did you noticed a Yellow Warning band on your Access when you open the db.
    You must Enable all macros to your db.
    maybe the location of your db is not yet in Trusted Location.

  5. #5
    DDP is offline Novice
    Windows 11 Access 2016
    Join Date
    Jan 2025
    Posts
    2
    Quote Originally Posted by jojowhite View Post
    did you noticed a Yellow Warning band on your Access when you open the db.
    You must Enable all macros to your db.
    maybe the location of your db is not yet in Trusted Location.
    I found the problem.
    For some reason the allow edits in the forms property sheet was set to no, once i set it to yes it worked.

    Thanks for all your help and i will try Ranman256 fix

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

Similar Threads

  1. Replies: 3
    Last Post: 10-13-2014, 05:48 PM
  2. Replies: 1
    Last Post: 09-04-2014, 11:10 AM
  3. Replies: 2
    Last Post: 08-11-2014, 12:57 PM
  4. Replies: 13
    Last Post: 12-05-2013, 06:04 PM
  5. Replies: 16
    Last Post: 04-30-2012, 07:12 AM

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