Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Entering values into a textbox on a non-modal form

Status
Not open for further replies.

CruiseMan

Programmer
Nov 17, 2006
29
US
I am trying to allow a user to enter a value into a textbox on a modeless (non-modal) form. Because of other background events occurring, the form must be non-modal. The form displays correctly, and I have loaded labels with no problem, but I cannot get focus on the textbox long enough to enter a value. Processing control returns to the calling form or process. Am I trying to do something that a non-modal form cannot handle?

example:

' frmManualData contains a textbox in which the user needs to ''enter a value.

DoEvents 'Handle any pending events prior to form load.
frmManualData.Show vbModeless, frmCallingForm
DoEvents

'Control returns to calling form without giving the user the
'opportunity to enter a value into the textbox. The frmManualData 'for is still visible, but no focus.
 
If you want this your parent form should not perform any focus-stealing operations (e.g. SetFocus calls on controls).
 
How about "showing" your form in code with the text box again after the other form or action has completely loaded or finished.
You can show a form as many time as you like if it is already showing.

Or you can also make the text entry form stay on top of all other forms without it being modal by using the following -

Code:
'In declarations
Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Dim Success

Sub Form_Load()
Success = SetWindowPos(frmManualData.hWnd, -1, 0, 0, 0, 0, 1) 'always on top of previous loaded forms or applications
End Sub

What are the DoEvents for? - they are usually frowned on!
 
>Am I trying to do something that a non-modal form cannot handle?

Dunno. Only one window can have focus at a time under Windows. So if you are doing anything on any other form in your application that requires focus while the non-modal form is displaying then the non-modal form will lose focus. Which is what dilettante was getting at.

>Because of other background events occurring, the form must be non-modal

Well no, not necessarily. This tends to be the case if you drive your code from a form (e.g. your startup object is a Form, and all your code is in forms), but can be better managed if you drive your program from a module (e.g. your startup object is Sub Main)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top