Page 2 of 2 FirstFirst 12
Results 16 to 26 of 26
  1. #16
    kathiepreston is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2021
    Posts
    33
    This is how the code is setup in the Module.

    Private Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

    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

  2. #17
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Well, does that look like the code at the link I gave you?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #18
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    It isn't enough to just add PtrSafe to your 64-bit compatible declarations.
    You also need to change Long to LongPtr for all handles/pointers such as hWnd etc

    So in this case, change these two lines to:
    Code:
    hwndOwner As LongPtr
    hInstancePtr As Long
    There's nothing at the moment on my website about converting to 64-bit (though something is planned for later in the year)
    However, here are two very useful links:
    https://codekabinett.com/rdumps.php?...ion-vba-64-bit
    Windows API Viewer for MS Excel (rondebruin.nl)

    However, it is unnecessary to API declarations to open specified files
    Much easier to use FileDialog code which works in either bitness.
    See Application.FileDialog property (Access) | Microsoft Docs
    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

  4. #19
    kathiepreston is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2021
    Posts
    33
    This is how it's in the module. Hope it helps

    #Private Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

    Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As LongPtr
    hInstance As LongPtr
    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 LongPtr
    lpfnHook As LongPtr
    lpTemplateName As String
    End Type


    Private Declare PtrSafe Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, _
    ByVal bRevert As Long) As Long


    Private Declare PtrSafe Function EnableMenuItem Lib "user32" (ByVal hMenu As _
    Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long


    Const MF_GRAYED = &H1&
    Const MF_BYCOMMAND = &H0&
    Const SC_CLOSE = &HF060&

    #

  5. #20
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Is all of this for opening a spreadsheet or doing a Save As or just selecting a spreadsheet to import/export?
    If just opening or selecting, it's a rather complicated method when you could just be using the msoFileDialog as suggested, which avoids API's all together.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #21
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Both the GetSystemMenu and EnableMenuItem APIs need to have the handles updated as previously explained.
    Also the two LongPtr items beginning with l...should be Long and not LongPtr as they aren't pointers.

    Having said all that I have a long distant memory from around 2014 that some old OpenFileName code doesn't work in 64-bit even after updating the APIs.
    I'd have to check whether its this code or not but I'd strongly recommend changing to FileDialog code anyway.
    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

  7. #22
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    OpenFileName code doesn't work in 64-bit
    I believe I saw that when I looked it up.

    also this: https://www.access-programmers.co.uk...lename.298463/
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  8. #23
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Thanks Moke.
    It seems my memory was indeed correct. I even contributed to that thread at AWF.
    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

  9. #24
    kathiepreston is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2021
    Posts
    33
    Thank you guys so much!! I can't tell you how much your help has meant. I'm about to go home but will look at the link tomorrow and try to figure it out.
    Again. Thank you very much!

  10. #25
    kathiepreston is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2021
    Posts
    33
    Well Folks it looks like I got it to work!! Thank you so much for all your help!! There is no way I would have been able to figure it out on my own! The GetMyFile code was exactly what I needed.
    Again, thank you! Thank you! Thank you! Thank you!

  11. #26
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Congratulations on getting it to work. No idea what you mean by the 'GetMyFile code'. Do you mean FileDialog?
    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 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Scope of Public Functions
    By GraeagleBill in forum Programming
    Replies: 7
    Last Post: 05-26-2021, 09:37 AM
  2. Replies: 1
    Last Post: 04-12-2020, 12:52 PM
  3. Replies: 4
    Last Post: 01-25-2019, 09:03 PM
  4. Public Functions and Private Subs
    By d9pierce1 in forum Programming
    Replies: 15
    Last Post: 11-28-2018, 09:25 AM
  5. Public Functions for Command Buttons
    By d9pierce1 in forum Forms
    Replies: 10
    Last Post: 11-25-2018, 01:57 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