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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rookie question about using a form instead of msgbox 2

Status
Not open for further replies.

knighthawke

IS-IT--Management
Mar 22, 2005
9
US
Hi,

I am trying to use a form so that I can customize it (graphically). I want to add an OK button but I don't want the user to be able to do anything else until they click the OK button. I want them to acknowledge that they have at least seen the form (I know no one really reads them...)

I am using VB6 and I know how to create a new project, design the form and add a button. I can do a little coding for the button (like end) so that when the user clicks it the form closes properly. My problem is that the user never HAS to hit the OK button. They can open other apps or ignore this warning form altogether. I have looked in the properties for the form but I cannot discern how to always keep the form on top and in focus until they click OK.

You guys can do this in your sleep, judging from my looking through the forum for this answer and seeing all the other REALLY tough things you have done.

I appreciate your ideas (I appreciate your code more :) but suggestions are also welcome.

Thanks for your help...

KH
 
Open your message form modally.
Code:
frmMessage.Open vbModal
This will force the the code execution to stop until the form is closed.


zemp
 
Zemp,

Thank you very much for your idea. My problem is that I don't know where to insert the frm.Message.Open vbModal

I tried this, got an object required error and debugged. The Frm.CompNotice.Open vbModal was hilighted in yellow.


Private Sub Form_Load()
Frm.CompNotice.Open vbModal
End Sub

Have I put this in the right place?

Thanks

KH
 
Place that code in the calling form. When you want to display your message.

Code:
in form1...

Private sub Command1_Click()
  if ..... then
   .. do something
  else
    frmMessage.Open vbModal
  endif
End Sub

zemp
 
Zemp,

I may be hopeless. My entire program is just the one form that opens with a button on it. No logic takes place. All my button does is just acknowledge the user has seen it by not going away until they click it. The form stays on top, with focus until they click the button and then the app closes.

The way I read your code (below) is that there is a button, on a form, with code that makes a decision (if then do) When the button is clicked it displays a message form (frm.Message).

In my case there is just the one form. Would what I want be some kind of load event rather than open? (if such exists) thinking that when the exe runs my form pops up with the button for them to click.

I know how busy you must be and I appreciate your time. It has given me an idea of maybe trying to use 2 forms someway.

Thanks again,

KH

in form1...

Private sub Command1_Click()
if ..... then
.. do something
else
frmMessage.Open vbModal
endif
End Sub
 
Add a module from the project window then change the startup object to Sub Main Project menu -> Project Properties

Then add this to the Module:
public sub main()
if ..... then
.. do something
else
frmMessage.Open vbModal
endif
end sub



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
I was assuming that your message form is called from a second form. It doesn't have to be. Wherever you would have used the VB message box function you can call your message form with the code provided (module, class, etc.).

zemp
 
Dr. JavaJoe

I did what you suggested except that I do not need any logic taking place.

Public Sub main()

frmMessage.Open vbModal

End Sub

I got an error message stating the 'method or data member not found' and the .Open was highlighted. I then backspaced through the .open and a menu popped up with lots of opens when I clicked the . Open was not one of the listed items but .Show was listed. I tried it and did not get an error but the form was not forced to keep focus either. It was like the vbModal did not work for the .Show method.

Any thoughts?

KH
 
hmmm, well you could force it on top of other windows like this:

Option Explicit
Private Declare Sub 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)
Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Sub main()
Form1.Show
SetWindowPos Form1.hWnd, HWND_TOPMOST, 0, 0, 0, 0, (SWP_NOMOVE Or SWP_NOSIZE)
End Sub



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Dr Java Joe... You Da Man!

It took me awhile to figure out where to put things but it is 'workin' like a new one' now.

Many thanks!

Also, Thanks to Zemp who also spent a lot of tutoring time with me today!

Thanks again!!

KH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top