5

We have been using MS Access database (Office 2007, 32bit) in Windows 7 for a long time but recently we switched into Office 2016, 64 bit.

Now every form is displaying the following message and it's really irritating:

this message

Moreover, the Access window is not getting minimized. I'm not an expert in VBA and don't know what to do. I'm pasting the codes. Please don't suggest any article or documentation provided by Microsoft. I have tried to understand those a lot and failed.

The code being used is:

Option Compare Database
Private Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

And:

Private Sub Form_Load()
    Application.RunCommand (acCmdAppRestore)
    SetWindowPos Application.hWndAccessApp, 0, 0, 0, 0, 0, 0
    Application.DoCmd.MoveSize 0, 0
End Sub

Previously (in 32-bit office) the Access window used to be hidden on form load but now in 64-bit it's wide open. Please help me to hide the MS Access window in 64-bit version.

2 Answers 2

8

Upgrading companies software without extensive test is amateurish!

But if that error message is the only problem you are lucky. You need to convert the api arguments declaration to x64, what usually means change allLongdeclarations of handles and pointers to LongPtrand add PtrSafe after Declare.

With the conditional compiler (#If VBA7 Then) Office 2010 and later use the first part, as they support VBA7 (LongPtr), Office 2007 and earlier use the else part with the old declaration.

#If VBA7 Then
    Private Declare PtrSafe Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As LongPtr, ByVal hWndInsertAfter As LongPtr, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
#Else
    Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
#End If

This can be found at Declaring API Functions In 64 Bit Office. Seems like you do not use x86 ActiveX controls or ODBC connections, because they cause trouble too.

You should read the Compatibility Inspector user's guide to get prepared for more trouble;)

6
  • Thanks a lot but using "Private Declare PtrSafe Function SetWindowPos Lib "user32.dll" (ByVal hwnd As LongPtr, ByVal hWndInsertAfter As LongPtr, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long" gives the same result. For time being I'm switching into Access 2016, 32-bit version. :( You are correct I should read the Compatibility Inspector user's guide. Thanks dude, Thanks a lot.
    – Imtiaz
    Commented Jun 17, 2019 at 11:09
  • Absolute no need gor office x64, unless you meet conditions in Choose between the 64-bit or 32-bit version of Office, but mist of them are better covered by a RDBMS. Did your project compile? Bet there are other parts that need adjustment. Commented Jun 17, 2019 at 13:58
  • Yes, my project compiled in 32-bit Access 2016 perfectly so not worried about that now. Thanks for your time man.
    – Imtiaz
    Commented Jun 17, 2019 at 16:01
  • Did it compile in x64? Commented Jun 17, 2019 at 16:02
  • 1
    Upgrading companies software without extensive test is amateurish! - this comment is completely unnecessary. OP is asking for a solution not an option whether what they're doing is wise.
    – t3chb0t
    Commented Jul 8, 2021 at 7:13
1

I agree with ComputerVersteher for the first part, so I'll address the second part of your question. You can make the form invisible by doing this:

Private Sub Form_Load()
    'this turns the forms timer event on every 1 milisecond
    Me.TimerInterval = 1
End Sub

Private Sub Form_Timer()
    Me.Visible = False
    'this turns the timer event off so you don't waste CPU power
    Me.TimerInterval = 0
End Sub
2
  • It should hide the form being used but I'm looking for a way to hide the MS Access window when the form is loaded and visible.
    – Imtiaz
    Commented Jun 17, 2019 at 11:11
  • 1
    And withSetWindowPosyou can set height and width to 0 (args cy, cx) what makes window invisible Commented Jun 17, 2019 at 16:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.