VBA - Can't get sendmessage + WM_CLOSE to work

Posted on 2006-05-17
Last Modified: 2012-06-27

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 ?
Question by:joyrider
    LVL 7

    Accepted Solution

    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.

    LVL 58

    Expert Comment

    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?

    LVL 34

    Expert Comment

    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

    LVL 34

    Expert Comment

    woow.. I was on the phone and didn't refresh.
    LVL 58

    Expert Comment

    There is also: "RunCommand acCmdProperties", but it's a toggle.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now