Results 1 to 6 of 6
  1. #1
    stalk is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    143

    How to handle code- to work both in 32 bit and 64 bit environment using PtrSafe keyword...

    My code below is failing after else part in 64 Bit..
    If Win64 Then
    Private Declare PtrSafe Function apiShellExecute Lib "shell32.dll" _


    Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
    As Long
    Else
    Private Declare Function apiShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
    As Long
    End If

    Thank you in Advance

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    You're not using conditional compilation correctly. Try this
    Code:
    #If VBA7 Then
    Private Declare PtrSafe Function apiShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" _
    (ByVal hwnd As LongPtr, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
    As LongPtr
    #Else
    Private Declare Function apiShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
    As Long
    #End If

    Note the additional use of LongPtr where needed
    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

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I've not seen code for 64 bit that looks like that (seems to be more concerned about Windows than Office) and have to wonder why the same code is repeated in the Else block. Then again, maybe your Access vba is more about Windows (such as API calls) than it is about Office programs.
    Maybe this will help

    https://docs.microsoft.com/en-us/off...tions-overview
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    stalk is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    143
    Gave me Compile error Invalid outside procedure at line IF VBA7 Then

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Post what you tried and paste rather than type out because what you just wrote is not what you were given

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Quote Originally Posted by stalk View Post
    Gave me Compile error Invalid outside procedure at line IF VBA7 Then
    The code I gave you is from one of my apps and it works
    You need to include the # symbols in each part of the conditional compilation code
    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

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

Similar Threads

  1. Replies: 3
    Last Post: 02-17-2018, 02:28 PM
  2. Syntax error in Keyword Search code
    By bsegge in forum Programming
    Replies: 10
    Last Post: 10-03-2016, 12:40 PM
  3. Replies: 4
    Last Post: 04-30-2014, 06:39 PM
  4. Code Does not work
    By larabeelw in forum Access
    Replies: 11
    Last Post: 11-27-2013, 03:18 PM
  5. Replies: 0
    Last Post: 10-07-2013, 09:37 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