Results 1 to 6 of 6

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

  1. #1
    stalk is offline Advanced Beginner
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    87

    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 Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,689
    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 (Mendip Data Systems) : Website, email
    If this has helped, please click the star button and leave a comment

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    6,206
    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
    - "doesn't work" is no help. Post err msgs and where.
    - Use code tags for code/sql. Implement changes in copies of your database.

  4. #4
    stalk is offline Advanced Beginner
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    87
    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
    6,206
    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 Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,689
    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 (Mendip Data Systems) : Website, email
    If this has helped, please click the star button and leave a comment

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
  •  
Tech Forums: Microsoft Office Forums