Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Aug 2002
    Posts
    33

    Question Unanswered: How to Suppress MsgBox (not error related)

    I have an ActiveX Control that keeps poping up a stupid msgbox thinking there is an error where there is none. It's a known bug they plan to fix next decade. I suspect that the control is using a On error resume next command being that the msgbox looks like a standard vbcritical msgbox.

    Is there any way to suppress msgbox so I can turn this false error off?

    I will be doing my own error handling, and will not need the error handling of the activex control. I've already tried setwarnings = false and my own on error.

    Thanks

    Example, the code should be able to supress a msbgox like this.

    TurnoffMsgBox = True
    call MsgBox("This should not display", vbcritical + vbokonly)
    TurnoffMsgBox = False

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Comment out the code?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Aug 2002
    Posts
    33
    I cant comment out the code imbedded in the ActiveX Control.

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    So this is error related.
    Just because you can't explain an error doesn't mean it's not happening.

    Have you thought about uncommenting the "On Error goto..." and use good old fashioned debugging to see what the problem is?
    EDIT: Just read the last post. Have a look in the helpfiles for break on errors
    George
    Home | Blog

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    what would happen with "set warnings off"?

    just a thought, makes me ashamed to admit I even thought of it......
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Aug 2002
    Posts
    33
    setwarnings will turn off any error messages related to update queries, record deletions and such.

    I'm sorry, I threw a comment in there that I should not have. You can disregard the On Error statement I made. The msgbox that is poping up is not a real error.

    The ActiveX control is checking for a condition, and if it is present(or not in this case), it then warns the user by calling a msgbox function. It is not tripping a real error condition.

    I don't want it to do this, so I want to supress any msgboxes before I call this particular function, then turn it back on.
    Last edited by absoffthewake; 07-17-07 at 14:16.

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Fancy telling us which activeX component and maybe a screenshot?
    Alternatively post a sample of your database that the "error" occurs in?
    George
    Home | Blog

  8. #8
    Join Date
    Aug 2002
    Posts
    33
    Quote Originally Posted by georgev
    Fancy telling us which activeX component and maybe a screenshot?
    Alternatively post a sample of your database that the "error" occurs in?
    I don't see why that would be nessesary.

    I just need to be able to supress msgbox. Stop complicating it!

  9. #9
    Join Date
    Jul 2006
    Posts
    108
    dude its not that simple. i wish there were a command something along the lines of msgboxes.allow = false but there isint and probably never will be so unless your willing to let these fine gentlemen help you then stop crying.

  10. #10
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Haha, well put jwalker!
    The problem is obvously not as easy as you'd like it to be - we're just trying to help. If you don't co-operate then what can you expect in return?
    George
    Home | Blog

  11. #11
    Join Date
    Aug 2002
    Posts
    33
    I have no problem co-operating, but I can assure you that the focus needs to remain on supressing a msgbox. That has nothing to do with my activex control.

    Thats not crying, thats keeping things focused.

    Now for you guys out there that are smart enough to see where I'm coming from, I found this code on some website and tried it out, but I can't get it to work, not even for a msgbox I call. I'm guessing it was origionally for vb. It basically hooks into the msgbox, captures the text, then closes the msgbox.

    Option Explicit
    Private Declare Function GetForegroundWindow Lib "user32" () As Long
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
    Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
    Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal zlhHook As Long) As Long



    'Purpose : To capture any Msgbox's shown on this thread
    'Inputs : bEnabled If True switches on msgbox capturing, else switches off.
    'Outputs : N/A (see the function zCaptureMsgbox where the contents of the msgbox are printed)
    'Notes : PLACE IN A MODULE. Can only be used within the application process.


    Function MsgboxCapture(bEnabled As Boolean)
    Const WH_CBT = 5 'Respond to certain system actions, making it possible to develop computer-based training (CBT) for applications (WH_CBT).
    Dim lThread As Long, lhInst As Long
    Static slhHook As Long

    If bEnabled = False Then
    lThread = GetCurrentThreadId
    slhHook = SetWindowsHookEx(WH_CBT, AddressOf zCaptureMsgbox, App.hInstance, lThread)
    Else
    'Release the CBT hook
    UnhookWindowsHookEx slhHook
    End If
    End Function

    'Private call back function used to capture and close and MsgBox's
    'Notes : PLACE IN A MODULE
    Private Function zCaptureMsgbox(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Const WM_CLOSE = &H10&, HCBT_ACTIVATE = 5
    Const clMaxText As Long = 255
    Const WH_MSGFILTER = (-1)

    Dim sClassName As String * clMaxText, sMsgboxText As String * clMaxText
    Dim lHwndWindow As Long, lNumChars As Long, lHwndText As Long

    If lMsg = 6 Then
    lHwndWindow = GetForegroundWindow
    lNumChars = clMaxText
    lNumChars = GetClassName(lHwndWindow, sClassName, lNumChars)
    If UCase(Left$(sClassName, lNumChars)) = "#32770" Then
    'The active window is a Msgbox, get the message and close it
    lHwndText = FindWindowEx(lHwndWindow, 0&, "Static", vbNullString)
    lNumChars = clMaxText
    lNumChars = GetWindowText(lHwndText, sMsgboxText, lNumChars)
    Debug.Print "Message box captured: " & Left$(sMsgboxText, lNumChars)
    Call SendMessage(lHwndWindow, WM_CLOSE, 0&, 0&)
    End If
    End If
    zCaptureMsgbox = 0
    End Function


    'Demonstration code (PLACE IN A FORM)
    Private Sub Command1_Click()
    MsgboxCapture False
    MsgBox "Hello Doesn't show"
    MsgboxCapture True
    MsgBox "Hello Does show"
    End Sub



    I had to make a change to make it work for vba, but I guess I did something wrong becuase it does nothing, no error, no close. Maybe you guys can help me figure it out? The change I had to make was there is no App.hInstance call in vba, so I've tried:

    Application.hWndAccessApp &
    0&

    I got this from another forum: "However, according to MSDN, this value (App.hInstance) is ignored in Windows NT/2000/XP, so you could just put 0& in its place."

    I think i'm 95% there, but I need to make this code work for VBA and I've not been successful. Any genious out there that can see what I'm not seeing??

  12. #12
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by absoffthewake
    Now for you guys out there that are smart enough to see where I'm coming from
    And with that I bid you: Good luck
    George
    Home | Blog

  13. #13
    Join Date
    Aug 2002
    Posts
    33
    any takers?

  14. #14
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Interesting code. I'll take a look at it sometime this next week/weekend (best I can offer.)

    Just be a little bit careful on how you word things as you may offend some people. (remember - we don't see the expressions on your face, don't know you, and have to judge you by what you write. You've come off pretty strong so far.)
    Last edited by pkstormy; 08-02-07 at 13:20.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  15. #15
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    When debugging, I got a compile error: Invalid use of AddressOf Operator in the
    slhHook = SetWindowsHookEx(WH_CBT, AddressOf zCaptureMsgbox, app.hInstance, lThread)
    line
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •