Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    Common Dialog

    I downloaded the Common Dialog from Microsoft. It's written for 32 bit. I added this to the code to make it work with 64 bit:
    #If VBA7 Then 'use PtrSafe


    Private Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias _
    "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
    #ElseIf Win64 Then 'need datatype LongPtr
    Private Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias _
    "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As LongPtr
    #Else '32-bit Office
    Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
    "GetOpenFileNameA" (pOpenfilename As OpenFilename) As Long
    #End If

    When I use the LaunchCD command, it doesn't open the window to pick a file. It gives me an error saying that a file was not selected and deletes the field it was supposed to save the path to. Here's the code for the button:
    Private Sub btnSelectPicture_Click()

    SubjectPicture = LaunchCD(Me, "C:\Pictures")
    UpdatePicture

    End Sub

    I'm not sure if I need an updated version of the Common Dialog or if there is another way to choose a file.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    perhaps you can clarify what LaunchCD is (you say a command but I don't see it) and how that relates to GetOpenFileName.

    beyond that, SubjectPicture doesn't appear to be declared - is that the field you are talking about?

  3. #3
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    SubjectPicture is the field in my table that the image is going to show (C:\Pictures\Rock.jpg)
    LaunchCD is a downloaded code that Microsoft put out so that we can pick files from a computer (Common Dialog)
    Here is the code I downloaded along with the code to make it work in 64 bit:


    'http://support.microsoft.com/kb/888695

    #If VBA7 Then 'use PtrSafe
    Private Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias _
    "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
    #ElseIf Win64 Then 'need datatype LongPtr
    Private Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias _
    "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As LongPtr
    #Else '32-bit Office
    Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
    "GetOpenFileNameA" (pOpenfilename As OpenFilename) As Long
    #End If

    Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
    End Type

    Function LaunchCD(strform As Form, Optional InitialFolder As String = "C:") As String
    Dim OpenFile As OPENFILENAME
    Dim lReturn As Long
    Dim sFilter As String
    OpenFile.lStructSize = Len(OpenFile)
    OpenFile.hwndOwner = strform.Hwnd
    sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0) & _
    "JPEG Files (*.JPG)" & Chr(0) & "*.JPG" & Chr(0)
    OpenFile.lpstrFilter = sFilter
    OpenFile.nFilterIndex = 1
    OpenFile.lpstrFile = String(257, 0)
    OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
    OpenFile.lpstrFileTitle = OpenFile.lpstrFile
    OpenFile.nMaxFileTitle = OpenFile.nMaxFile
    OpenFile.lpstrInitialDir = InitialFolder
    OpenFile.lpstrTitle = "Select a file using the Common Dialog DLL"
    OpenFile.flags = 0
    lReturn = GetOpenFileName(OpenFile)
    If lReturn = 0 Then
    MsgBox "A file was not selected!", vbInformation, _
    "Select a file using the Common Dialog DLL"
    Else
    LaunchCD = Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) - 1))
    End If
    End Function

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    FYI the Windows common dialog control isn't installed with Windows 10 and doesn't work in 64-bit Access.
    MS have never updated it for 64-bit and it's seems unlikely they ever will.

    The MS article you quoted is for Access 2003/2007.

    When I first ran my apps using 64-bit Access a few years ago I had to replace all my code that used GetOpenFileName when browsing for files as it no longer worked.
    So although your conditional compilation code is fine, it still won't work AFAIK.

    However, if you are determined to persevere, try adding conditional compilation to the Private Type section
    E.g hWnd is a pointer so needs LongPtr
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I would like to make this work. Since I'm still in my beginning stages of coding, would really appreciate help getting it to work. How do I go about it?

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    perhaps use filedialog instead - plenty of examples can be found on the web, just google 'vba filedialog'

    https://docs.microsoft.com/en-us/off...ion.filedialog

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Having read your original post again, it seems you want an image file viewer not a CD player ....
    You could try this example app on my website http://www.mendipdatasystems.co.uk/f...wer/4594429467
    It allows you to view thumbnails of all image files in a folder.

    Even if that' not what you want, it includes code to browse for a file which you can use

    HTH
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Showing the image is no problem. I already have that set up. What I'm looking to do is to have the user select a file (which can be anywhere, including a USB drive) and to have it copy the file to my server and save the server path to a field on my table. Will those do that?

  9. #9
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I found this article on the FileDialog. Hoping it will show me how to do it:
    https://analystcave.com/vba-applicat...g-select-file/

  10. #10
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I figure I'll try to code it slowly so that I can get a window to choose the file I want first. I downloaded the database and checked the code. The database works fine on my computer, so I figure that I'd use the code. I also checked the article I found. The code is basically the same. So, I used them both.

    Is FileDialog something I have to define? I tried using the code in the database and also in the article I found. It goes to the debugger and gives me an error:
    Click image for larger version. 

Name:	Error.jpg 
Views:	28 
Size:	109.1 KB 
ID:	36117

    The database I downloaded works fine, so I tried to locate where it might define FileDialog, but couldn't find it.

  11. #11
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Did you look at the file dialog code in the example app I suggested. You can use that even if the rest of the code isn't any use of you
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  12. #12
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Yes. That's where I got that code. I couldn't find anywhere it was defined though.

  13. #13
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    To use that code in your own application, you need to add the VBA reference Microsoft Office XX.0 Object Library where XX is the Office version e.g. 14 for Access 2010.

    This isn't included in the references list for all versions of Access so you may need to browse for the file MSO.DLL
    e.g. in the location C:\Program Files\Common Files\Microsoft Shared\Office 14\MSO.DLL
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  14. #14
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I don't know how to do that. Would you mind giving me a way to do it?

  15. #15
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Open the VB Editor. Click Tools...References.
    Look in the list for that library and tick it if it's there.
    Otherwise, click Browse and search for it, select it when found to add to the list.
    See the third screenshot in this thread https://www.access-programmers.co.uk...d.php?t=302291

    Close and reopen your Access app, return to the VBE, click Debug...Compile.
    It should accept the new code (though you may have other errors of your own that will need fixing)
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 10-27-2017, 01:09 PM
  2. Creating 'Common' VBA code
    By Nevsky78 in forum Programming
    Replies: 4
    Last Post: 06-18-2012, 02:07 AM
  3. common form fields
    By soulice in forum Forms
    Replies: 9
    Last Post: 04-05-2012, 02:58 PM
  4. Play sounds and Common Dialog Box example
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-29-2010, 06:49 AM
  5. Common Dialog control / ShowOpen method
    By phuile in forum Forms
    Replies: 0
    Last Post: 04-10-2009, 12:16 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