Results 1 to 8 of 8
  1. #1
    11panos04 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2020
    Posts
    4

    Need help with a clicking button

    It is nice to find you,my english is not my main language,so sometimes i ll run into mistakes etc not intentionally.

    So,i have a mini form as my main one with many buttons.One of them when clicked opens a new form.In that form i have reference pics and below each pic another button.Now,what i tried to do is that,since i m completely useless when it comes to coding etc.I made a table with an attachment field, so i can have the attachments bound to the accdb file wherever i take it(not a path to it in my pc).I want,whenever i click a specific button in that form,to open that specific attachment,for example a pdf file.I don t want all the field,but i need i.e. for pic 1-attachment 1, for pic 2-attachment 2 etc. I d like it to be with click on button functionality.If not,clickable pics would work for me as well.

    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Using attachments could cause your db to fill past the maximum, which is why you should store the PATH to the document.
    then it can be opened via click.
    As an attachment, it is a recordset.
    so you must create a recordset to extract another recordset,then open the result.

  3. #3
    11panos04 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2020
    Posts
    4
    Can you direct me into doing that?

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    paste this code into a module. (Alt-F11, insert , module)
    Then it will open ANY file via its extension....
    .pdf files will open in acrobat,
    .doc files in word
    etc


    USAGE:
    OpenNativeApp txtBox
    'opens item in field in native app


    Code:
    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
    
    
    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

  5. #5
    11panos04 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2020
    Posts
    4
    Couldn t do it.Obviously i ve done something wrong.

  6. #6
    11panos04 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2020
    Posts
    4
    Any further help?

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    "Couldn't do it" means what - error message, wrong result, nothing happens?

    If you want to open attachment field item in another application, will have to first extract to a folder location then use Ranman code to open file.

    Extracting file from attachment field requires more code. https://accessjitsu.com/2015/10/03/v...ent-data-type/
    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.

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    OP appears to be using 64bit access, so the declarations need to be changed

    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

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

Similar Threads

  1. Clicking a button programmatically
    By peterFisp in forum Forms
    Replies: 6
    Last Post: 09-26-2019, 06:38 PM
  2. Replies: 4
    Last Post: 08-25-2019, 12:16 PM
  3. Automating Button Clicking
    By csn102 in forum Programming
    Replies: 3
    Last Post: 11-05-2015, 02:01 PM
  4. Replies: 2
    Last Post: 09-15-2015, 03:08 AM
  5. Comments when clicking a button
    By Juan4412 in forum Programming
    Replies: 4
    Last Post: 06-23-2011, 04:34 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