• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2343
  • Last Modified:

VBA - Can't get sendmessage + WM_CLOSE to work


i've got the little problem that sometimes the property window appears in my access database when i don't want it. this happens very rarely but it's anoying.

I was thinking that i could use the sendmessage api to close the dialog in question. I already know the classname of the dialog it's : " OArgDlg" so i do the following :

Const WM_CLOSE = &H10
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

thehwnd = FindWindow("OArgDlg", vbNullString)
Debug.Print thehwnd '(to see if it actually found the window and it does)
SendMessage thehwnd, WM_QUIT, 0, 0&

and it does not work even doh it finds the window so it's something with the sendmessage that's not working for the sake of testing i saw if it worked with internet explorer when the page was google (thehwnd = FindWindow(vbNullString, "Google - Microsoft Internet Explorer")) again it found the window (thehwnd > 0) but the send message did not work.

I tried postmessage as well but that didn't work either. I also tried other window messages like WM_Hide etc but nothing seems to happen so i think i have something wrong with either my sendmessage api declaration or the sendmessage command itself.

anyone any idea how to get sendmessage working in ms access ?
  • 2
  • 2
1 Solution
Jonathan KellyCommented:
If your using Access 2000 you can set the Allow Design Changes Property of the form to 'Design View Only'
This will stop the property dialog from appearing when the form is in Form View.

Hello joyrider

The property sheet for forms and controls appears when the form is not in design view? If that is the problem, open each form in turn and set "Allow Design changes: Design View Only", which should be the default anyway...

This being said, you sample works with "SendMessage thehwnd, 16&,0&,0&". Maybe the wrong constant?

Why not just disable them all the together from the users view:

Tools -> Option -> StartUp -> And untick the checkboxes.

To open the database so you can see them, hold down the shift key when opening it

woow.. I was on the phone and didn't refresh.
There is also: "RunCommand acCmdProperties", but it's a toggle.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now