Question vba in 2003 not working in 2007

codexproject

New member
Local time
Today, 14:29
Joined
Oct 22, 2009
Messages
9
Hi I have these codes:

CLASS MODULE:

Option Compare Database
Option Explicit


Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, _
ByVal bRevert As Long) As Long

Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As _
Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long

Private Declare Function GetMenuItemInfo Lib "user32" Alias _
"GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As _
Long, lpMenuItemInfo As MENUITEMINFO) As Long

Private Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type

Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060&

Public Property Get enabled() As Boolean
Dim hWnd As Long
Dim hMenu As Long
Dim result As Long
Dim MI As MENUITEMINFO

MI.cbSize = Len(MI)
MI.dwTypeData = String(80, 0)
MI.cch = Len(MI.dwTypeData)
MI.fMask = MF_GRAYED
MI.wID = SC_CLOSE
hWnd = Application.hWndAccessApp
hMenu = GetSystemMenu(hWnd, 0)
result = GetMenuItemInfo(hMenu, MI.wID, 0, MI)
enabled = (MI.fState And MF_GRAYED) = 0
End Property

Public Property Let enabled(boolClose As Boolean)
Dim hWnd As Long
Dim wFlags As Long
Dim hMenu As Long
Dim result As Long

hWnd = Application.hWndAccessApp
hMenu = GetSystemMenu(hWnd, 0)
If Not boolClose Then
wFlags = MF_BYCOMMAND Or MF_GRAYED
Else
wFlags = MF_BYCOMMAND And Not MF_GRAYED
End If
result = EnableMenuItem(hMenu, SC_CLOSE, wFlags)
End Property


GENERAL MODULE:

Option Compare Database
Option Explicit

Function InitApplicationDisabled()
Dim c As closecommand
Set c = New closecommand

'Disable Close menu.
c.enabled = False
End Function
Function InitApplicationEnabled()
Dim c As closecommand
Set c = New closecommand

'Enable Close menu.
c.enabled = True
End Function


FORMS MODULE:

Option Compare Database
Option Explicit



Private Sub disable_Click()
Call InitApplicationDisabled
End Sub

Private Sub enable_Click()
Call InitApplicationEnabled
End Sub


=================

when I click the disable button, yes the close button of the access window does really is disabled but when I put my cursor on top of close button and click it, it still closes the access application. however when I right click the mouse, you can see that its close menu is disabled. WHATS WRONG WITH 2007?

I am using MS Access 2007 sp2.

Do I lack something here?
 
can someone advice or assist me on this problem !

the reason you're not getting any leads is because its a sloppy post. no code tags, and it's LONNNNNNNNNGGGGGGGGGG
 
what do you mean sloppy post? no code tags and long.

I have seen topic name that is no sense and even more longer than this post. actually i think they never read the post how to talk to a programmer of yours. but still got some replies.
 
what do you mean sloppy post? no code tags and long.

When you post code wrap it in code tags. See the button (#) in the Advanced view. This retains multiple spaces so the code is formatted and indented properly making it easier to read. Pasting into the ordinary part of post removes repeated spaces because it is just ordinary html.

You have not been selective about which code you posted. eg You didn't really need to post the button click code. You also could have trimmed it down to the disable code since this is wht you asked about.

The general impression is that you have done little to understand the code and just dumped it here for us to sort out.

Then you give a very poor description followed by shouting "WHAT IS WRONG WITH 2007"

Your followup post looks more like a demand than a request. No "please" and ending in an exclamation mark.

My impression is that the code disables the Close command in the menu but I don't think it does anything to the close window button.
 

Users who are viewing this thread

Back
Top Bottom