Results 1 to 12 of 12
  1. #1
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376

    32 vs 64 bit issue

    Hello all,
    I am not that familiar with VBA and have run across an issue with 32 vs 64 bit versions. This came up out of the blue when I opened a database that I hadn't worked on in months ( I did open it on a new computer as I had to replace my old one).
    The error states;

    Compile Error:
    The code in the project must be updated for use on 64 bit systems. Please review and update Declare statement and then mark them with the PtrSafe attribute.

    Here is the code that is high lited in red.



    Private Declare Function ts_apiGetOpenFileName Lib "comdlg32.dll" _
    Alias "GetOpenFileNameA" (tsFN As tsFileName) As Boolean


    Private Declare Function ts_apiGetSaveFileName Lib "comdlg32.dll" _
    Alias "GetSaveFileNameA" (tsFN As tsFileName) As Boolean


    Private Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long

    I have no idea what this is referring to or how to correct it. Can someone please assist in correcting it.

    Edit: I borrowed this code from the internet, I did not write it, hence my inability to correct it because of my in depth lack of knowledge of VBA

    Thanks
    Dave
    Last edited by Dave14867; 04-18-2020 at 06:27 AM. Reason: More Info

  2. #2
    CarlettoFed is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    274
    You have to replace:
    Private Declare Function ts_apiGetOpenFileName Lib "comdlg32.dll" _
    Alias ​​"GetOpenFileNameA" (tsFN As tsFileName) As Boolean

    Private Declare Function ts_apiGetSaveFileName Lib "comdlg32.dll" _
    Alias ​​"GetSaveFileNameA" (tsFN As tsFileName) As Boolean

    Private Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
    with
    #If VBA7 Then
    Private Declare PtrSafe Function ts_apiGetOpenFileName Lib "comdlg32.dll" Alias ​​"GetOpenFileNameA" (tsFN As tsFileName) As Boolean

    Private Declare PtrSafe Function ts_apiGetSaveFileName Lib "comdlg32.dll" Alias ​​"GetSaveFileNameA" (tsFN As tsFileName) As Boolean

    Private Declare PtrSafe Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
    #else
    Private Declare Function ts_apiGetOpenFileName Lib "comdlg32.dll" _
    Alias ​​"GetOpenFileNameA" (tsFN As tsFileName) As Boolean

    Private Declare Function ts_apiGetSaveFileName Lib "comdlg32.dll" _
    Alias ​​"GetSaveFileNameA" (tsFN As tsFileName) As Boolean

    Private Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
    #endif


  3. #3
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Just to add to CarlettoFed's response:

    If all users have A2010 or later (32-bit or 64-bit), you only need the 3 lines of code contained in the #If VBA7 section
    Conditional compilation (#If VBA7 Then …#Else … #End If) is only required if any users are running A2007 or earlier as those don't have VBA7.

    Having said that, you may well have issues with using the old common controls reference, comdlg32.dll, whilst running 64-bit Windows10.
    If so alternative code will be needed that provides the same functionality
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  4. #4
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    Sorry for the late reply to this but Health issues have kept me away. I tried what was suggested but I still get errors. Below is the total section that is giving me the issues, it is used to browse for a file. the Red text section is the what is hi-lited by the debugger.

    Private Declare Function ts_apiGetOpenFileName Lib "comdlg32.dll" _
    Alias "GetOpenFileNameA" (tsFN As tsFileName) As Boolean


    Private Declare Function ts_apiGetSaveFileName Lib "comdlg32.dll" _
    Alias "GetSaveFileNameA" (tsFN As tsFileName) As Boolean


    Private Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long






    Private Type tsFileName
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    strFilter As String
    strCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    strFile As String
    nMaxFile As Long
    strFileTitle As String
    nMaxFileTitle As Long
    strInitialDir As String
    strTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    strDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
    End Type


    ' Flag Constants
    Public Const tscFNAllowMultiSelect = &H200
    Public Const tscFNCreatePrompt = &H2000
    Public Const tscFNExplorer = &H80000
    Public Const tscFNExtensionDifferent = &H400
    Public Const tscFNFileMustExist = &H1000
    Public Const tscFNPathMustExist = &H800
    Public Const tscFNNoValidate = &H100
    Public Const tscFNHelpButton = &H10
    Public Const tscFNHideReadOnly = &H4
    Public Const tscFNLongNames = &H200000
    Public Const tscFNNoLongNames = &H40000
    Public Const tscFNNoChangeDir = &H8
    Public Const tscFNReadOnly = &H1
    Public Const tscFNOverwritePrompt = &H2
    Public Const tscFNShareAware = &H4000
    Public Const tscFNNoReadOnlyReturn = &H8000
    Public Const tscFNNoDereferenceLinks = &H100000

  5. #5
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Dave
    Did you read the responses by CarlettoFed or myself?
    API declarations have to be updated for 64-bit.
    However you may have issues with this particular code anyway.
    Suggest you use alternative code as already suggested.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  6. #6
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    Colin,

    Yes I did read and I tried what CarlettoFed suggested but I still got the same error. I will look for code examples on the web.

  7. #7
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    For info, if you use conditional compilation, the 32-bit section is highlighted in red when the database is opened in 64-bit. That is normal behaviour.
    However, as you didn't post any evidence of conditional compilation, I've no idea whether that is all your code.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  8. #8
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    Colin, I have no idea what you are referring to, maybe it is a setting in Office that isn't correct (in VBA) after the new install in my new Laptop I am using now.

  9. #9
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Below is an example of conditional compilation in use in 64-bit Access.
    The #If VBA7 section works in 64-bit.
    The #Else section would be used in 32-bit Access and is shown in red when running 64-bit Access.

    Click image for larger version. 

Name:	Capture.PNG 
Views:	18 
Size:	45.5 KB 
ID:	41731

    Does that make sense now? If not, I suggest you research conditional compilation online
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  10. #10
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    Colin,

    Yes, thanks for the example, That's exactly what I am seeing. makes sense now.

    Thank You

  11. #11
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    Colin,
    It looks like the code I got off the internet was very old and from 1999 and used for mdb files. It is a module and doesn't work with 64 bit apparently. Can you suggest a better way to browse for a file that works with newer systems?

    Thanks
    Dave

  12. #12
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    I did point that out previously in post #3
    Quote Originally Posted by isladogs View Post
    you may well have issues with using the old common controls reference, comdlg32.dll, whilst running 64-bit Windows10.
    If so alternative code will be needed that provides the same functionality
    I suggest using file system object instead. Lots of info available online.
    This link may get you started: https://docs.microsoft.com/en-us/off...mobject-object
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

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

Similar Threads

  1. Replies: 5
    Last Post: 01-08-2015, 02:08 PM
  2. CDate and CStr issue with "Invalid Use of Null" Issue
    By excellenthelp in forum Queries
    Replies: 3
    Last Post: 07-25-2014, 01:34 PM
  3. QRY Issue
    By buckwheat in forum Access
    Replies: 1
    Last Post: 09-19-2013, 11:48 AM
  4. Replies: 22
    Last Post: 05-21-2013, 07:54 PM
  5. End if issue
    By raytackettsells in forum Programming
    Replies: 4
    Last Post: 03-22-2012, 10:21 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