Transfer from 32 bit to 64 bit machine

User avatar
Carol W.
3StarLounger
Posts: 390
Joined: 26 Jan 2010, 16:02
Location: Las Vegas, NV

Transfer from 32 bit to 64 bit machine

Post by Carol W. »

Access 2010

I have an application that has been running on a Win XP SP3 (32 bit) machine for years. I'm trying to get it to run on a new Win 7 64 bit machine. I copied all the files, linked whatever tables I could (one was not in an Access format, but that's a whole other story) and I get the following compile error (see screenshot).
32 bit code.jpg
How do I fix this so it runs on a 64 bit machine?

Thanks in advance.
You do not have the required permissions to view the files attached to this post.
Carol W.

User avatar
Carol W.
3StarLounger
Posts: 390
Joined: 26 Jan 2010, 16:02
Location: Las Vegas, NV

Re: Transfer from 32 bit to 64 bit machine

Post by Carol W. »

Please ignore. I found the answer myself (with the help of Google).

Private Declare PtrSafe Function ....

Thanks anyway.
Carol W.

User avatar
HansV
Administrator
Posts: 78530
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Transfer from 32 bit to 64 bit machine

Post by HansV »

Jan Karel Pieterse has written an article about this: Excel: Declaring API functions in 64 bit Office. Although it's for Excel, it applies to Access too. The article and the links explain what you'd need to change.

The definition of OPENFILENAME and the declarations would become

Code: Select all

Type OPENFILENAME
  lStructSize As Long
  hwndOwner As LongPtr
  hInstance As LongPtr
  lpstrFilter As String
  lpstrCustomFilter As String
  nMaxCustFilter As Long
  nFilterIndex As Long
  lpstrFile As String
  nMaxFile As Long
  lpstrFileTitle As String
  nMaxFileTitle As Long
  lpstrInitialDir As String
  lpstrTitle As String
  flags As Long
  nFileOffset As Integer
  nFileExtension As Integer
  lpstrDefExt As String
  lCustData As Long
  lpfnHook As LongPtr
  lpTemplateName As String
End Type

Private Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" _
  Alias "GetOpenFileNameA" (OFN As OPENFILENAME) As Boolean

Declare PtrSafe Function GetSaveFileName Lib "comdlg32.dll" _
  Alias "GetSaveFileNameA" (OFN As OPENFILENAME) As Boolean
This will not work in Access 2007 or before. For compatibility, you can use this:

Code: Select all

#If VBA7 Then

Type OPENFILENAME
  lStructSize As Long
  hwndOwner As LongPtr
  hInstance As LongPtr
  lpstrFilter As String
  lpstrCustomFilter As String
  nMaxCustFilter As Long
  nFilterIndex As Long
  lpstrFile As String
  nMaxFile As Long
  lpstrFileTitle As String
  nMaxFileTitle As Long
  lpstrInitialDir As String
  lpstrTitle As String
  flags As Long
  nFileOffset As Integer
  nFileExtension As Integer
  lpstrDefExt As String
  lCustData As Long
  lpfnHook As LongPtr
  lpTemplateName As String
End Type

Private Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" _
  Alias "GetOpenFileNameA" (OFN As OPENFILENAME) As Boolean

Declare PtrSafe Function GetSaveFileName Lib "comdlg32.dll" _
  Alias "GetSaveFileNameA" (OFN As OPENFILENAME) As Boolean

#Else

Type OPENFILENAME
  lStructSize As Long
  hwndOwner As Long
  hInstance As Long
  lpstrFilter As String
  lpstrCustomFilter As String
  nMaxCustFilter As Long
  nFilterIndex As Long
  lpstrFile As String
  nMaxFile As Long
  lpstrFileTitle As String
  nMaxFileTitle As Long
  lpstrInitialDir As String
  lpstrTitle As String
  flags As Long
  nFileOffset As Integer
  nFileExtension As Integer
  lpstrDefExt As String
  lCustData As Long
  lpfnHook As Long
  lpTemplateName As String
End Type

Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
  Alias "GetOpenFileNameA" (OFN As OPENFILENAME) As Boolean

Private Declare Function GetSaveFileName Lib "comdlg32.dll" _
  Alias "GetSaveFileNameA" (OFN As OPENFILENAME) As Boolean

#End If
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78530
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Transfer from 32 bit to 64 bit machine

Post by HansV »

Carol W. wrote:Please ignore. I found the answer myself (with the help of Google).

Private Declare PtrSafe Function ....
Great! But you need a bit more: the definition of OPENFILENAME has to be updated too. And if you want to be able to use the database both in Access 2010 and in earlier versions, you need a special modification. See my previous reply.
Best wishes,
Hans

User avatar
Carol W.
3StarLounger
Posts: 390
Joined: 26 Jan 2010, 16:02
Location: Las Vegas, NV

Re: Transfer from 32 bit to 64 bit machine

Post by Carol W. »

Thank you, Hans. I will look at that article and I will change the definititon of OPENFILENAME.

Both machines now run Access 2010 (I upgraded the 32 bit machine to Office 2010 a little over a month ago) so backward compatibility isn't an issue.

:thankyou:
Carol W.