You're in luck!
See my example app - Create a web version checker
#If VBA7 Then 'Add PtrSafe - required for 64-bit Office (VBA7)
Declare PtrSafe Function acb_apiGetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
#ElseIf Win64 Then 'need datatype LongPtr
Declare PtrSafe Function acb_apiGetTickCount Lib "kernel32" Alias "GetTickCount" () As LongPtr
#Else '32-bit Office
Declare Function acb_apiGetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
#End If
Hi. I believe Isladog's approach is just trying to cover all bases. It may not be required for some situations, but it may be necessary for others. For example, do you have any Access 2007 or earlier users?I noticed you use this kind of code for 64/32 bit Windows or Office
Is it really required?Code:#If VBA7 Then 'Add PtrSafe - required for 64-bit Office (VBA7) Declare PtrSafe Function acb_apiGetTickCount Lib "kernel32" Alias "GetTickCount" () As Long #ElseIf Win64 Then 'need datatype LongPtr Declare PtrSafe Function acb_apiGetTickCount Lib "kernel32" Alias "GetTickCount" () As LongPtr #Else '32-bit Office Declare Function acb_apiGetTickCount Lib "kernel32" Alias "GetTickCount" () As Long #End If
I have no problem declaring all as PtrSafe and compile it and make it works both under Office 64 or 32 bit
'CR - APIs updated 07/10/2019
'###############################################
#If VBA7 Then 'for use with 32/64-bit Access (2010 onwards)
[B] Declare PtrSafe Function acb_apiGetTickCount Lib "kernel32" Alias "GetTickCount" () As Long[/B]
#Else 'for A2007 (or earlier)
Declare Function acb_apiGetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
#End If
Hi smig/DBGuy
You're both right!
The code was written in about 2012 when most of my clients were still using A2007. With the advent of A2010 (32-bit & 64-bit), VBA7 was introduced and I started using conditional compilation for all possible client configurations.
However the API code I used then was over complicated & in this case also contained some mistakes .
I have used this opportunity to simplify & correct the APIs in this app.
As I still have some clients using A2007, I still use conditional compilation.
The example you posted has been changed to:
Code:'CR - APIs updated 07/10/2019 '############################################### #If VBA7 Then 'for use with 32/64-bit Access (2010 onwards) [B] Declare PtrSafe Function acb_apiGetTickCount Lib "kernel32" Alias "GetTickCount" () As Long[/B] #Else 'for A2007 (or earlier) Declare Function acb_apiGetTickCount Lib "kernel32" Alias "GetTickCount" () As Long #End If
If all of your users are on A2010 or later you just need the lines in bold type. Similarly for the other APIs in this app.
Hope that helps & thanks for alerting me to this.
I have posted the update to sample databases as well
#If OfficeIs64Bit Then
' code for 64 bit Office
#Else
' code for 32 bit Office
#End If
Function IsWin32OrWin64()
'Determine if operating system is 32-bit or 64-bit
'-------------------------------------------------
'Modified from code provided at:
' http://www.vb-helper.com/howto_get_os_name.html
Dim proc_query As String
Dim proc_results As Object
Dim Info As Object
proc_query = "SELECT * FROM Win32_Processor"
Set proc_results = GetObject("Winmgmts:").ExecQuery(proc_query)
For Each Info In proc_results
IsWin32OrWin64 = Info.AddressWidth & "-bit"
Next Info
'Debug.Print IsWin32OrWin64
End Function
Function IsOfficex64()
'checks if Office is 32 or 64 bit
#If Win64 Then
IsOfficex64 = "64-bit"
#Else
IsOfficex64 = "32-bit"
#End If
'Debug.Print IsOfficex64
End Function
The ribbon is irrelevant to any discussion about APIs.
You are very fortunate that all your users have the same Access version. As they all use 2010, all have VBA7. This means you can scrap conditional compilation and just use the VBA7 version of the declaration as it will work with both 'bitnesses'.
You may occasionally need to do conditional #If Win64 Then statements for items that only work in 64-bit but that's rarely necessary.
However you do need to realise that some VBA references (e.g. ComnonControls) and certain ActiveX controls (including Flexgrid and Treeview) do not work in 64-bit. In such cases you will need to rewrite your code
Oh, I see... For that, and Colin can correct me if I am wrong, but I think you may have to go to the Registry to find out. Check out Colin's demo on finding out the version and bitness to see how he did it. Cheers!I already understood, from this discussion , that I only need the VBA7 style of declaration (What I already had)
If we go back to the start of the topic, what I wanted to do is to let the users automatically find and download an update version of my app.
For this I should know if the user is running the 32 or 64 bit version of Office.
The ribbon is irrelevant to any discussion about APIs.
You are very fortunate that all your users have the same Access version. As they all use 2010, all have VBA7. This means you can scrap conditional compilation and just use the VBA7 version of the declaration as it will work with both 'bitnesses'.
You may occasionally need to do conditional #If Win64 Then statements for items that only work in 64-bit but that's rarely necessary.
However you do need to realise that some VBA references (e.g. ComnonControls) and certain ActiveX controls (including Flexgrid and Treeview) do not work in 64-bit. In such cases you will need to rewrite your code
EDIT
Posts crossed. I use the following code in a standard module to detect /report the bitness
Code:Function IsWin32OrWin64() 'Determine if operating system is 32-bit or 64-bit '------------------------------------------------- 'Modified from code provided at: ' http://www.vb-helper.com/howto_get_os_name.html Dim proc_query As String Dim proc_results As Object Dim Info As Object proc_query = "SELECT * FROM Win32_Processor" Set proc_results = GetObject("Winmgmts:").ExecQuery(proc_query) For Each Info In proc_results IsWin32OrWin64 = Info.AddressWidth & "-bit" Next Info 'Debug.Print IsWin32OrWin64 End Function Function IsOfficex64() 'checks if Office is 32 or 64 bit #If Win64 Then IsOfficex64 = "64-bit" #Else IsOfficex64 = "32-bit" #End If 'Debug.Print IsOfficex64 End Function
Have a look at my Access Version checker app https://www.access-programmers.co.uk/forums/showthread.php?t=302910
Function IsOfficex64()
'checks if Office is 32 or 64 bit
#If Win64 Then
IsOfficex64 = "64-bit"
#Else
IsOfficex64 = "32-bit"
#End If
'Debug.Print IsOfficex64
End Function
Hmm, I'm not entirely sure but I believe conditional compilation constants won't show you anything. It's only visible to the compiler. You know, just before the code runs? Like I said earlier, you may have to go to the Registry instead.I look at this code and wonder if the "#If Win64" show the Office 32/64 bit version or the OS one ?
Code:Function IsOfficex64() 'checks if Office is 32 or 64 bit #If Win64 Then IsOfficex64 = "64-bit" #Else IsOfficex64 = "32-bit" #End If 'Debug.Print IsOfficex64 End Function
Yes, I looked at your codeSorry.
Confusingly, I posted code that checks the OS bitness - IsWin32OrWin64 as well as code that checks the Office bitness - IsOffice64.
Both of these do work. No need to use the registry.
Although the registry does contain information about versions and bitness, I mainly use WMI code to extract information about hardware, OS and software such as Office.
Both DBG and I linked to my Access version checker app.
The really difficult bit was detecting whether users are running Office 365 or the retail version of Office 2016/2019. This was made really complicated by all using the same range of version info 16.0.....+
Function IsOfficex64()
'checks if Office is 32 or 64 bit
#If Win64 Then
IsOfficex64 = "64-bit"
#Else
IsOfficex64 = "32-bit"
#End If
'Debug.Print IsOfficex64
End Function
Hi. I hope this doesn't add any confusions, but check out this link.Yes, I looked at your code
I'm looking into the IsOfficex64 one, and there you check for Win64.
I like it's simplicity, but does it realy check for the Office64/32 or for the OS ?
This one made me confused and I want to make sure
Code:Function IsOfficex64() 'checks if Office is 32 or 64 bit #If Win64 Then IsOfficex64 = "64-bit" #Else IsOfficex64 = "32-bit" #End If 'Debug.Print IsOfficex64 End Function
Hi. I hope this doesn't add any confusions, but check out this link.
Sorry about that. But the way I read it, Win64 does reflect if the Office environment is 32- or 64-bit. For example, let's take a look at the Conclusion paragraph of this article, it says:I already looked at this, and it totally confused me
i trust Colin
Conclusion
VBA 7.0 is the latest version of VBA that improves the performance of applications that are created in Office 2010. To enable you to continue using your legacy solutions in different versions of Microsoft Office, the VBA7 compilation constant is available. Likewise, because there is now a 32-bit version and 64-bit version of Office 2010, you use the Win64 compilation constant to direct the compiler to the run the correct section of code in your VBA applications.
#If VBA7 Then
…
#ElseIf Win64 Then
…
#Else
…
#End If
#If VBA7 Then
#If Win64 Then
...
#Else
...
#End if
#Else
...
#End If
Sorry about that. But the way I read it, Win64 does reflect if the Office environment is 32- or 64-bit. For example, let's take a look at the Conclusion paragraph of this article, it says:
Whew! Glad to hear we got it somewhat clarified now. I still recommend you take a look at Colin's demo in case it can provide some more hints for you. Cheers!Thanks,
This make it more clear now
You distinguish the Office version by the way the compiler run the code