Moving from x32 to x64 (1 Viewer)

deletedT

Guest
Local time
Today, 03:41
Joined
Feb 2, 2019
Messages
1,218
After years of wondering what to do, I decided to move from 32 bit to 64.
Now, I'm trying to migrate my databases to 64 bit version of Access.

Following Microsoft documents and several sample databases here, I added the following to my code:
Code:
'###########################################
#If VBA7 Then[COLOR="YellowGreen"]  'Add PtrSafe - required for 64-bit Office (VBA7)[/COLOR]

#ElseIf Win64 Then [COLOR="YellowGreen"]'need datatype LongPtr[/COLOR]

#Else [COLOR="YellowGreen"]'32-bit Office[/COLOR]

#End If
'###########################################

Now In VBE, the section of Declare left for 32 bit version, shows as red.
But when I compile the code, no error comes out.

Is it what it should be?
Doesn't codes in Red mean some kind of Error?

 

Attachments

  • 2019-02-26_10-18-31.jpg
    2019-02-26_10-18-31.jpg
    55.4 KB · Views: 264
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:41
Joined
Oct 29, 2018
Messages
21,473
Hi. Are you using 64-bit Access in that screenshot? Just curious...
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:41
Joined
Oct 29, 2018
Messages
21,473
Hi. I only have 32-bit and I don't get the red lines. Not sure why yours is red. Maybe that's how it is with 64-bit. Can you try the same code in a 32-bit Access?
 

deletedT

Guest
Local time
Today, 03:41
Joined
Feb 2, 2019
Messages
1,218
Hi. I only have 32-bit and I don't get the red lines. Not sure why yours is red. Maybe that's how it is with 64-bit. Can you try the same code in a 32-bit Access?

I've already tested it. No Red codes in 32 bit.
And the app runs without any problem in both versions.

But still the red color is strange in 64 bit.

This is from 32 bit:

 

Attachments

  • 2019-02-26_11-37-52.jpg
    2019-02-26_11-37-52.jpg
    57 KB · Views: 242

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:41
Joined
Oct 29, 2018
Messages
21,473
Okay, we'll have to wait for other 64-bit users to chime in and confirm or tell us if there's really anything wrong. My guess is you're okay. Cheers!
 

isladogs

MVP / VIP
Local time
Today, 03:41
Joined
Jan 14, 2017
Messages
18,221
Having the #Else part in red is expected behaviour when running the code in 64-bit.

When I first converted I used the same conditional compilation as you have with three sections. In fact I still have that in a lot of apps....BUT its totally unnecessary.

Use
#If VBA7 with PtrSafe and LongPtr for pointers like hwnd ...for anyone running A2010 or later whether 32 or 64 bit

and
#Else part for anyone on A2007 or earlier

See a detailed answer I wrote here the other day
https://www.access-programmers.co.uk/forums/showpost.php?p=1613249&postcount=14
 
Last edited:

deletedT

Guest
Local time
Today, 03:41
Joined
Feb 2, 2019
Messages
1,218
Having the #Else part in red is expected behaviour when running the code in 64-bit.

When I first converted I used the same conditional compilation as you have with three sections. In fact I still have that in a lot of apps....BUT its totally unnecessary.

Use
#If VBA7 with PtrSafe and LongPtr for pointers like hand ...for anyone running A2010 or later whether 32 or 64 bit

and
#Else part for anyone on A2007 or earlier

See a detailed answer I wrote here the other day
https://www.access-programmers.co.uk/forums/showpost.php?p=1613249&postcount=14

Since all users here are running on Office 2016 and above (All in 32 bit and me in 64) I'll deleted the conditional section and simply add PtrSafe and LongPtr.
At present I'm too busy and can't read the link. I'll take a look tonight.
Million thanks for your time and support.
 

bdra2778

Registered User.
Local time
Yesterday, 19:41
Joined
Feb 14, 2019
Messages
34
Okay, we'll have to wait for other 64-bit users to chime in and confirm or tell us if there's really anything wrong. My guess is you're okay. Cheers!
Hello, I am using MS Access 365 x64, and it same to you, the seccion after #ELSE is in red, all my programs runs ok.

Note: only I had had problems with this program "www .access-programmers.co.uk/forums/showthread.php?t=303846" than doesnt run in x64 only in x32
 

Attachments

  • Access vba7 x64.png
    Access vba7 x64.png
    16.4 KB · Views: 65

sonic8

AWF VIP
Local time
Today, 04:41
Joined
Oct 27, 2015
Messages
998
I've already tested it. No Red codes in 32 bit.
And the app runs without any problem in both versions.

But still the red color is strange in 64 bit.
The red color in the 32bit-code is normal in 64bit VBA. The parser for syntax highlighting processes all code regardless of conditional compilation conditions.

Nevertheless, this is not a problem at all because the compiler does not process the code when you are in the 64-bit-environment.



You might want take note of my text on Windows API in 64-bit-VBA for further reference.
 

deletedT

Guest
Local time
Today, 03:41
Joined
Feb 2, 2019
Messages
1,218
Hello, I am using MS Access 365 x64, and it same to you, the seccion after #ELSE is in red, all my programs runs ok.



Note: only I had had problems with this program "www .access-programmers.co.uk/forums/showthread.php?t=303846" than doesnt run in x64 only in x32
Thanks for letting me know.
 

deletedT

Guest
Local time
Today, 03:41
Joined
Feb 2, 2019
Messages
1,218
Code:
You might want take note of my text on Windows API in 64-bit-VBA for further reference

I strongly recommend everyone read the article referenced
https://codekabinett.com/rdumps.php?Lang=2&targetDoc=windows-api-declaration-vba-64-bit

Sonic8 is the guru on this subject and the article is very well written.

After this section:
Misconception: “You should change all Long variables in your Declare Statements and Type declarations to be LongPtr variables when adapting your code for 64-bit.”

Wrong!

it's been explained:

Only if a function parameter or return value is representing a pointer to a memory location or a handle (e.g. Window Handle (HWND) or Picture Handle), it will be a 64-bit Integer. Only these types of function parameters should be declared as LongPtr.

To be true, it's very confusing. Now I have to search to see which one needs to be changed to LongPtr and which one doesn't..:banghead::confused:
I don't understand why Microsoft makes everything this complicated. After years of delay on office x64, now this.....
 

isladogs

MVP / VIP
Local time
Today, 03:41
Joined
Jan 14, 2017
Messages
18,221
Two more references you should find useful:

1. WinAPI Viewer by Ron de Bruin
https://www.rondebruin.nl/win/dennis...sapiviewer.htm
This lists a large number of APIs in both 32-bit & 64-bit versions. Its listed as 'for Excel' but is equally useful in Access

2. Win32API_PtrSafe.TXT -- Declare statements for Visual Basic for Applications and Microsoft Office 2010
This is probably the most comprehensive reference by MS - see attached

And another brief thread with several methods - not all equally good in my opinion. In fact one is incorrect.
https://www.access-programmers.co.uk/forums/showthread.php?t=299801&highlight=Conditional+compilation
It also has the above items
 

Attachments

  • Win32API_PtrSafe.zip
    137.8 KB · Views: 64
Last edited:

sonic8

AWF VIP
Local time
Today, 04:41
Joined
Oct 27, 2015
Messages
998
To be true, it's very confusing. Now I have to search to see which one needs to be changed to LongPtr and which one doesn't..:banghead::confused:
Thank you for the feedback. It has been remarked that the quoted text is rather unspecific. I will try to add some more detailed guidance on what has to be changed and what not.


In function declarations you usually get away with everything being declared as LongPtr, even if that is not correct, it will not make much of a difference. However, in user defined types you need to take really good care to get it right. There it will make the difference between the API call working and not working.
 

Users who are viewing this thread

Top Bottom