Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Set Focus On A Msgbox?

Hi, is there a way to set focus on a message box? :O

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Msgbox Focus...?
anyone know how to give a MsgBox system Focus? similar to how a system error or critical error msgbox is brought to the front/ontop even if it's minimized

Msgbox Having Focus
if there anyway of making sure that a message box is on top of any other window on the screen.

I am running winsock and sending remote messages. when the message box appears on the client it appears on the task bar behind everythig else

any ideas???

Focus After Msgbox
Environment: VB 5.0 (service pack 3)
System: NT WorkStation or Win95

After use Msgbox, the next command (Setfocus) don't run correct. It's crazy. The focus don't go to the control indicate. Please help me.


Msgbox Out Of Focus After Retry
If anyone could help, I need to get rid of the msgbox to proceed with my program after the user clicks Retry.


Msgbox - How To Bring In To Focus
I would like to know how to bring a msgbox in to focus.

I have a program that starts up another application and sends keys and mouse movements to this other application. I need to popup a msgbox at some point but unfortunately, as the other application is in focus and maximized the msgbox is hidden.

Is there any way to bring the msgbox to the top most window?
I'd rather not minimize every window that may be in front of msgbox as the windownames are dynamic.

MsgBox Focus Question
I have a project that the user works two windows at once split so they are visible on the same screen.. Form1 is the main VBP project and works in junction with an OCX that controls a third party viewer. When the user clicks save on Form1 it has the focus. Then it calls the OCX which displays a msgbox which is under form1. The reverse happens when the user makes selections on the viewer. It has focus and when control passes back to form1 and displays a message it is under the viewer. How can I make the message box stay in front of both forms? I tried me.setfocus in the OCX and it doesn’t seem to support it. Someone pointed me at an API that is called SetWindowPos but it doesn’t seem to work. “Using MsgBox "test", vbMsgBoxSetForeground” seems to set it in front but I need to check for a yes no response.

Any suggestions?

MSGBOX Focus Problems
I've got an MDI form with many children. As events happen on various MDIChild forms, msgboxes are fired. They return a vbYesNoCancel value. My problem is the msgboxes are always launching BEHIND the child forms, making the application stall.

Everything was working perfectly until a couple days ago, and I changed SOMETHING that must be causing this. No, I don't remember what I changed, unfortunately.

I've even tried watching "me.caption" and it does indicate that the active form is the mdichild I want, right before the msgbox is launched.

Msgbox High Focus?
How do i make a message box that appears OVER all the other windows open.

Msgbox Button Focus
Is there a way to control the focus of the buttons
in a msgbox when there are 2 buttons?

vbYesNo box and I want to place the focus on the no button

Edited by - ootencl on 6/3/2004 12:35:31 PM

MsgBox Changes Form Focus
Hopefully a simple solution to this.

I have one form which can open another form where the user puts information in. If they put bad data in, a msgbox pops up. The problem is when the box opens, it sets focus back to the first form, but when you close it, focus returns to the data input form. Normally I would not care, but I kinda want them to see the data when the msgbox appears. How do I keep the msgbox from messing with the focus?

ReOrdering The Focus On A Msgbox Buttons
Hi I was wondering if any has any ideas on how to re-order the msgbox button focus so it's not always on the first button.


MsgBox "do you want to keep going", vbYesNoCancel

Places the initial focus on the Yes button, I want it to be on either the NO or Cancel button.


Focus Loss After Msgbox Display
Hello to everyone

I am using the keydown event in a MDIchild form to capture keyboard shortcuts(ex. Ctrl + PageUp). All works well until a shortcut activates one of several msgbox's. At this point the msgbox displays correctly-however the keyboard shortcuts no longer work. I have looked extensively on the net but have not seen an easy fix. I am assuming the msgbox receives focus as soon as it displays but doesn't allow the focus to shift. Any help is greatly appreciated.

Msgbox When Focus Is Lost On Picturebox
how do i make it so when the mouse is not on a picturebox anymore, it gives the user a msgbox. i tried using the lostfocus function, but it doesnt seem to do anything.

What Is The Command To Set The Focus Of This VBScript Msgbox To The NO Button Instead
What is the command to set the focus of this VBScript msgbox to the NO button instead of the YES?


<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
dim blnTest
blnTest = false

function form1_onsubmit()
if blnTest = true then
if msgbox("Are you sure you want to delete?" & vbcrlf & vbcrlf & _
"This action can NOT be undone!", vbyesno, "Confirm Delete") = vbyes then
Form1_OnSubmit = true
Form1_OnSubmit = false
end if
Form1_OnSubmit = false
end if

End function

Sub lstJob_onclick
blnTest = true
End Sub

Msgbox Causes Loss Of Focus After Validate Event Ends
I have a VB6 application with 3 text boxes. The user will normally move between the text boxes by clicking on each one or by tabbing. The particular problem I am about to describe has been identified in various other discussions, but with much more complicated controls and logic yet I could not find any resolution to those discussions.

Each text box has a validate event where I check the .text value using a standard function that I wrote to ensure it is a valid numeric. If the contents are not numeric then I set Cancel = True and the focus returns to the text box just as I want. If the contents pass the numeric test then they are subject to a "range" test. The purpose of this test is to detect and warn the user if the value appears outside a "normal" range. I use a msg box to interface with the user. If the user does not want to accept the value, then I set Cancel = True and the focus remains on the text box so the user can make a correction. However, when the user accepts the value, even though it is outside the normal range, I want the the focus to move to the control where they originally clicked or tabbed to.

Here's what happens when the mouse was clicked to move the focus from one textbox to another:
The validate event kicks off and the message box appears, Click ok, the control-lostfocus event occurs, the new control gotfocus event occurs, the text in the new control is selected (gotfocus set that up), but focus isn't really on the control. The mouse shape changes to an I-beam just as you would expect for entry in a textbox. The caret is flashing at the end of the selected text, but typing any character does not affect the contents of the control. In order for typing to be captured in the control I need to click the mouse. In fact I can click the mouse anywhere on the form and the focus returns to the desired control. The original text in the "new" control is no longer selected, although still present and any characters typed are added to the end of the existing character string. I want VB6 to perform the same set of actions when the next control is clicked as when the tab key is pressed (see below).

Here's what happens when the tab key is pressed to move the focus from one textbox to another:
Everything works as expected. The msgbox appears, lostfocus executes, gotfocus executes, the correct text is selected and any characters typed are entered into the appropriate text box.

I have attached a sample project based on my application. In this sample I have simplified the validate routine and the numeric validation routine. I have also reduced the msgbox to a simple "OK" from a "yes/no" one.


Finding Out The What Button Was Clicked In 'Msgbox' Code && Highlight On Focus...
For example...

    The user clicks a button to delete a name off a list (using a list object) and a Msgbox appears asking if he/she is sure...
Anyways if the user clicks yes, it gets deleted and No is clicked, it should do nothing. I can't figure out how to get the form to check which button was clicked.

Also... how do you highlight the text in a TextBox when it comes into focus at run-time, (whether selected by mouse or tab). It only places the cursor at the begining of the box without highlighting it. plz help...

How To Get Msgbox's Static Handle? How To Kill Or Skip Msgbox?
i now know how to send WM_COMMAND into normal buttons.
but i cant send it to a popup msgbox's "OK" button.
the reason is because it's handle keeps on changes everytime it pops up.
so, is there anyway to skip the error msgbox?

MsgBox VbSystemModal - How To Show Icon In The Msgbox?
When showing a msgbox as vbsystemmodal, how can you show the apps icon in the msgbox like if a msgbox was shown normally?

How To Give Focus To Activex Component On Form Focus?
Using the Reflections ActiveX component (Reflections is a popular Terminal Editor for connecting with old Alpha/VMS servers), I have a Form with this internal terminal editor ActiveX that obviously needs to have focus to type in.

I've tried setting Form_GotFocus and Form_Click to give focus to the activex component but to no avail. The only thing that works is if I set Form_Repaint to give focus, then it works fine. But repaint causes the window to constantly try to bring itself in front of other Microsoft apps like Word and Outlook and other VB apps when I drag them in front of it. And it keeps flashing in the task bar when I move something non-MS in front of it.

Is there a better way to keep focus on the activex terminal session when the form gets focus without using repaint?

Maintain Line Of Focus After Focus Is Lost On A Listbox ?
I have two listboxes on my firm.
In the first, one selects which Report DLL to use, and then when that is selected, my app creates a new instance of that DLL and loads up all available reports into the second listbox.

So you click on the first listbox, and the blue line select thang goes across that line to show you have selected something.
Just like any other listbox does.

But then you select an item for the second listbox, and the blue line disappears from the first listbox.

So when you're looking at the screen, if you don't remember which DLL you selected, you wouldn't actually know which DLL the second box is referring to.

Ideally the first listbox should retain that blue line while at the same time the second listbox should aswell.

Any thoughts ?

Form Got Focus Or Lost Focus Don't Work
Hi, I have a form that I can't get the Lost Focus or Got Focus events to fire, would anybody know why?

Here is what I am trying to accomplish. I have an .exe vb6 application(MainApp) that opens another .exe vb6(ChildApp) application using the shell command. The main application has a list view with a bunch of records. The ChildApp is used to Insert, Delete or UPdate records from the MainApp. So when an Insert, Update or Delete take place on the Child App, I'd like to refresh the listview on the MainApp because the records have changed. How can I accomplish this? Is there a way to call the form in the Main Application from the Child Application even they are 2 different .exe files? I really need help on this please.

Excel TextBox Font Changes When In Focus And Out Of Focus??
Hi All,

I am using a TextBox within an Excel Sheet and did set the font property to "Terminal" with size 22. When in focus, it seems to be OK but when I click somewhere else in the spreadsheet (TextBox losing focus) the font change. Why is that? I want the font to be the same in-focus or out-of-focus. Any help would be greatly appreciated. I have been playing with this for a while but could not figure it out. By the way, I am using Office 2003.
Thank you.


SendKey To A Window NOT In Focus - But Keep Focus?
Fyi, I'm fairly new to VB.

Anyway, to the point.
I have two applications, both running in full screen.
What I want to accomplish is that while one of the applications are running in focus (full screened), I want my VB program to run in the background and send a key on a regular basis to the other application (the one that is NOT in focus) without having to tab out of the focused application.

I managed to achieve some of this partly with the help of FindWindow and ShowWindow:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_HIDE = 0
Private Const SW_NORMAL = 1
Private Const SW_MAXIMIZE = 3
Private Const SW_SHOW = 5
Private Const SW_MINIMIZE = 6
Private Const SW_RESTORE = 9
Dim hinst As Long
Dim hinst2 As Long

hinst = FindWindow(vbNullString, "PrgNotInFocus") ' The program that should not be in focus, but have keys sent to
hinst2 = FindWindow(vbNullString, "PrgInFocus") ' Should be in focus at all times
If Not IsNull(hinst) Then
ShowWindow hinst, SW_NORMAL
SendKeys (1)
ShowWindow hinst, SW_MAXIMIZE
End If

This allows me to bring forth the window that I don't want in focus and "makes it press 1".
But that's hardly the effect I'm looking for, since it:

-Tabs out of my current application and focuses the wrong one
-Requires the window I want to SendKeys to to be focused


Get Focus Lose Focus (ASAP)
Hello I have a program that Gets the focus of a text box on intervals and need to "reset" the focus to the application that had the focus before i took it.

For an example:
I am useing internet explorer and the application gets the focus of the text box in my application then i want to "reset" the focus back to internet explorer !


Sorry Vikarmji - Still The Focus Goes There.Focus In Flexgrid - Pls Help Me

   My Flexgird contains 32 rows and 5 columns. Focus should not go to specific rows.Iam using the following code

Private Sub Msflexgrid_SelChange()
With MSflexgrid
 If .Row = 1 Or .Row = 11 Or .Row = 21 Or .Row = 26 Or .Row = 2 Or .Row = 12 Or .Row = 22 Or .Row = 27 Then
     .FocusRect = flexFocusNone
    .FocusRect = flexFocusLight
 End If
End With
End Sub

But it is not working properly.

Thanks in Advance


Edited by - dorathy_sylvia on 3/1/2005 8:37:41 PM

Opening A Form But Not Give It The Focus (or Quick Tell Me Wich Form Has The Focus)
Opening a form but not give it the focus (or quick tell me wich form has the focus). Is this possible??

Lost Focus /got Focus????
I have an exit button which when pressed displays a msg box. The msgbox asks 'are you sure you want to exit'. The trouble is that if the user selects no i cant find a way to put focus back to the conrol that had focus previously. Does anyone know how to do this and if so give me any pointers?


Focus, Focus, Fovus
What is the code to figure out if a control has focus? I would really like to code:
If SoAndSoControl.HasFocus Then
Do this or that
End If

Is there something similar?

Lost Focus-set Focus
On Lost focus I am checking the len of a text and want the focus to stay on that control
if a check fails , how do i do that
can i just do

Private Sub txtMCCN_LostFocus()
' Validate here if its is less
If (Len(txtMCCN) &lt; 6) Then
MsgBox ("MCCN has to be 6 chars long")
selFocus txtMCCN
End If
End Sub

Share what you know and ask what you dont....

Refresh A Form Not In Focus From A Form That Is In Focus
When in a program with mulitple forms, I would like to refresh a form that is not currently in focus from a form that is currently in focus.

I have a parent form that contains status information. I call a child form to change information that will affect the satus information display.

Currently I go back to the parent that was not in focus, and perform and perform a manual refresh, via a command button which changes the entries in the status line.

All variables in a common module and declared as public.

What instruction process can I use to change information on the parent form when changes are made on the child form.

Help With Msgbox
hi all, i am using this code to generate a MSGBOX


Validate = MsgBox("Game Information:" & vbCrLf & "----------" & vbCrLf & "Derby County" & vbCrLf & "vs" & vbCrLf & txtopposition.Text & vbCrLf & "----------" & vbCrLf, vbOKCancel, "Game Summary")

If Validate = 1 Then

All is working fine, but how can i make the back color of the msgbox use this colour &H00CFFEDC&

and the ok / cancel buttons = &H00FEECD8&

Many thanks

Msgbox Help

Is it possible to change the colours of a msgbox and its buttons to match the interface colours?

Help From Msgbox !!
can anyone please tell me how to connect to my help files through my msgbox
well i know that i have to give the help file name in and the context which i the number or index of the part of the help file which the required help exists
i have a help file made with html workshop
with .chm extension
and when i give its details to the message box it does appeasr but gives a error message as well saying the below

HH_HELP_CONTEXT called without a MAP Section


plz help

Msgbox Help
Im doing a game that has a form with a textbox to enter a name before the game starts. Well i made it so that it tells me i didnt enter a name but after i clikc ok on the msgbox the program starts up. How do you make it so it wont start up? here my code for that:

If EName1.Text = "" Then
MsgBox "You failed to enter your name, click ok and then enter your name"
End If

' Goes to the easy difficulty game

Let Form3.P1Name.Caption = Form2.EName1.Text
Let Form3.P2Name.Caption = Form2.EName2.Text


Msgbox Help
how do you change the font of the text in the msgbox? this is what i got but how do you change the font?

If txtCommand.Text = "3" Then
MsgBox ("You lose ha ha you are dead!!!!")
End If

Har et STORT problem..

sitter fremfor en tentamen, skal lage en msgbox i access, med spørsmål om å avslutte, og alternativene "JA" og "NEI", får til å få opp msgboxen, men alternativene fungerer ikke reiktig,

enten fungerer begge alternativene som ja, eller som nei, kan noen gi meg den komplette koden? slik at dette fungerer, sitter forresten med Visual basic 6 og access 2000

Msgbox Only Once
Im trying to implent a little algorithm that will display a message box stating rules... when a specific sheet in an excel workbook is opened. However i only want it to appear once and that is it... even if u switch from sheet to sheet and come back to that sheet. I was thinking of maybe putting it in the work book general declerations section with this code

Dim kk As Integer
kk = 0
If Worksheets("Parameters").Activate = True Then
MsgBox "Please Read The Rules Before Proceeding Any Further", MB_OK, "Warning!"
kk = 1
End If

however it is not working... any ideas?

I am trying to write the following code, but want to reference a cell in my message. I have the following code, but I am coming up with an error. What should the code read?

If Range("H92").Value > Range("J92").Value Then
MsgBox "This may be the last wire of the month. To meet the Forecasted Expense exactly, send wire of Range ("H92").value",vbExclamation,Forecast Alert!
End If

hey guys! im trying to write code that would continually add one to the score if the user gets the answer right. Also, im notifying the user through message boxes whether or not they got the right answer or not. im trying to display the user's current score everytime they get it right. i have this code but it doesnt seem to be working.

with ScoreCalc, the code wont show the correct answer (QuizA(i)) or even show the msgbox. also, with the other msgbox, the points are not displayed.

Public Sub cmdEnter_click()

Call ScoreCalc

End Sub

Public Sub ScoreCalc()

If txtAns1.Text = QuizA(i) Then
Call ScoreCalc2
MsgBox "You got the correct answer! You scored", points, "!"
MsgBox "Sorry, the correct answer was", QuizA(i), "!"
End If

End Sub

Public Sub ScoreCalc2()

pts = 0
points = pts + 1

End Sub

some suggestions and insight would be greatly appreciated.

MsgBox Help
could someone please give me the code so when i click exit on my program a msgbox comes up and asks if you want to quit. then if you click yes it ends and if you click no i goes back onto the program


Yes Or No Msgbox

how can i insert an yes or no msgbox to close a form?

Msgbox On Top
I am using Shell to execute another program and asking the user to move the mouse to a certain area and click on it so I can do work in that area. The reason I have to do it this way is because there are no shortcuts or keyboard commands that I could find to get me inside the listbox. Anyways, when I tell the user to move to this listbox, the msgbox will be in the background. How can I make the msgbox on top?? Thanks in advance.

sngnumhours = Val(Combountil) - Val(ComboStTimes)
If (Combountil) & (ComboStTimes) = same Then
MsgBox "you have entered incorrect information"
End If

this works but only when there are no entries in the until & sttimes boxes
what i am looking to do is if matches appear in until & sttimes then bring msgbox into play

any help once again welcom thanx

Help With MsgBox Plz
Ive got a 4x4 grid. each row and column is added up vertically and horizontally. the results appear in the labels. (labels are in arrays)

I have to create a msgbox that says congratulations... if the user can enter all the numbers in a grid which would total 56 on each row and column, and unlucky .... if they didnt succeed.

Could someone tel me whats wrong with this coding?

If lblResult(0).Caption = 56 Then
End If
If lblResult(1).Caption = 56 Then
End If
If lblResult(2).Caption = 56 Then
End If
If lblResult(3).Caption = 56 Then
End If
If lblResult(4).Caption = 56 Then
End If
If lblResult(5).Caption = 56 Then
End If
If lblResult(6).Caption = 56 Then
End If
If lblResult(7).Caption = 56 Then
MsgBox ("Congratulations! You have completed the Puzzle")
MsgBox ("Unlucky! Try Again")
End If

Msgbox ?
Does anyone know if you can change the text of a msgbox button.

Like instead of 'Yes No' to say 'True False'

I havent seen any evidence that you can from anywhere but i
just thought i would ask anyway.



Msgbox Help Please
Would any one happen to no how to make a (are you sure you want to quit) message box in Visual Basic 6.0

This is as far as i have goten

Private Sub UserForm_Terminate()
Dim exitmsgbox As String
exitmsgbox = MsgBox("Are you sure you want to Quit?", vbApplicationModal + vbYesNo, "Quit Appalication")

If exitmsgbox = vbYes Then
Unload Me

If exitmsgbox = vbNo Then
End If
End Sub

But even if i click no the program still Close's down Please Help me

how do i say that if the ok button is clicked on the msg then restart form well so far i got=

If (if you click ok)Then
Unload Me
End If
End Sub

how do you say if you clicked ok

MsgBox Help
I need a little help with a program I am working on. Its a joke for I person I work with. I am trying to set up a button so when the user clicks it a MsgBox pops up and gives a message. (Havent decided what to put in it yet)

Here is where I need help.
I need help trying to set it up so, if the user clicks Same button Again, another message box pops up BUT with a diffrent message.

I cant seem to get it right. Can anyone help me out with this?

Private Sub Command1_Click()
MsgBox "First Message", vbCritical

'*If the button is clicked again I want the next message to appear, and not the first.*'

MsgBox "Second Message", vbExclamation

End Sub

Any Help?

Help With Msgbox
Hi there

I have a userform, that is mailed using a commandbutton, now in the event that the user has not completed all the fields i.e. textbox1 has no value, then I want a message box to pop up and alert them to return to the form and complete the field, I have tried the following:

If textbox1.text =”” then msgvar = MsgBox("Please Enter Number", vbOKonlyl + vbInformation)

Select Case msgvar
Case vbokonly

End Select

The problem is this closed the form and all the info is lost, how do I get back to form without loosing anything, then complete the form and proceed to click the command button again, which will then process the form via mail.

Hope this makes sense


Copyright © 2005-08, All rights reserved