#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default UserForm

I use a user form in which the user shall enter a date in a text field. I
then have a sub that checks if the date is valid. If not so I show a message
box. However I want the program to show the message box and when the user
clicks OK I want the user form to still be shown.

Private Sub checkDate()
If (Not (IsDate(userForm1.TextBox1.Text))) Then
MsgBox ("Date not valid")
End If
If (Not (IsDate(userForm1.TextBox2.Text))) Then
MsgBox ("Date not valid")
Else: Call mainProgram
End If
End Sub

The problem is that I do not know how to write a sub that just shows the
user form.
Now I just have a sub that gives instructions when the user clicks a button
on the user form. This sub calls checkDate as you can see below.

Private Sub genereraRapportKnapp_Click()
Call checkDate
Call mainProgram
Unload Me
End Sub

The user form is created in a Modul when pressing a button.

Public Sub startKnapp_Click()
userForm1.Show
End Sub

If anyone has a clue how to solve this please help me, I seem to be quite
lost....Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default UserForm

Once the user form is shown, it won't go away until it's unloaded. You
can make it modeless if you want the user to be able to work "around"
it.

userForm1.Show vbmodeless

You already have the line to show the userform...

userForm1.Show

just put it in a sub.

sub ShowForm1 ()
userForm1.Show
end sub

You can then call the sub from other procedures if you want.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default UserForm

thank you ver much for your reply! However, when I call the sub that contains
the code:
userForm1.show

I get the message that the form is already displayed. I just want to go back
to the user form, preferably with the same info as the user already has
entered into the different fields. Do you see my problem? Any help you can
give me is very much appreciated!

Yours sincerly,

Franz Klammer

"ward376" skrev:

Once the user form is shown, it won't go away until it's unloaded. You
can make it modeless if you want the user to be able to work "around"
it.

userForm1.Show vbmodeless

You already have the line to show the userform...

userForm1.Show

just put it in a sub.

sub ShowForm1 ()
userForm1.Show
end sub

You can then call the sub from other procedures if you want.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default UserForm


If you show the form modeless and remove the "Unload Me" line from your
calling sub, the userform will "float" on top and "hold" any parameters
entered.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default UserForm

What I think you're doing....
1. You have a userform you created that has a button or two that checks
textboxes where you want folks to entere dates. If they entere dates
that are not valid, you pop up a message box to tell them. THE PROBLEM
is that once they click thorugh the message box, the form is blanked
out or unloaded or you just can't see it.

What I think you want to do....
A. Warn them
B. Don't dump the form

Get rid of the code "call main program"

All you need to do is run the code to check if it is a date or not then
pop the msgbox. Nothing else.



If you don't really care what info they put in there and just want to
warn them, highlight the text box when the exit the box.
Something like this:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsDate(TextBox1.Value) = False Then
TextBox1.BackColor = &HFF&
Else
TextBox1.BackColor = &HFFFFFF
End If
End Sub

if you really want to force them to enter the date appropriately,
(assuming you have a final button or routine they click to save their
entry....) just enter a snip of code in the routine that goes something
like this...

sub savebutton_click()
Dim DateFlag As Boolean
If IsDate(TextBox1.Value) = False Then DateFlag = True
If IsDate(TextBox2.Value) = False Then DateFlag = True
If IsDate(TextBox3.Value) = False Then DateFlag = True

If DateFlag = True Then
MsgBox "You need to enter the right date in the red boxes":
Exit Sub
End If
end sub

=====
Regards,
Jamie

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Userform to enter values and shown in same userform in list helmekki[_104_] Excel Programming 0 November 19th 05 03:23 PM
Looping procedure calls userform; how to exit loop (via userform button)? KR Excel Programming 6 July 27th 05 12:57 PM
Activating userform and filling it with data form row where userform is activate Marthijn Beusekom via OfficeKB.com[_2_] Excel Programming 3 May 6th 05 05:44 PM
Access from add_in userform to main template userform.... Ajit Excel Programming 1 November 18th 04 05:15 PM
Linking userform to userform in Excel 2003 missmelis01 Excel Programming 2 August 27th 04 08:07 PM


All times are GMT +1. The time now is 11:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"