Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default Simple Form questions

A command button on a sheet presents a form (Frm_Initial) which has a
textbox displaying information for the user, plus Ok and Cancel buttons
(where Cancel should exit the routine, and Ok present the next form)....
except that neither button works.

The initial button on the sheet:
Private Sub CommandButton1_Click()
Load Frm_Initial
Frm_Initial.Show
End Sub

and the form code:
Private Sub Cb2_Cancel_Click()
'user clicked Cancel
Unload Frm_Initial
End Sub

Private Sub Cb1_Ok_Click()
'user clicked OK
'Unload Me
Frm_SelectCert.Show
End Sub

What am I doing wrong, please?

Regards.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Simple Form questions

Add a public Property to your forms called UserAcepted as Boolean
In the Click event for OK, add UserAcepted = True.
Replace Unload Me with Me.Hide
Where your forms are launch the 1st form, do this...

frm_Initial.Show
If frm_Initial.UserAcepted = True then
frm_SelectCert.Show
If frm_SelectCert.UserAcepted = True then
frm_whatever
End If
End If

Basically, don't unload forms & control the showing of forms from 1 point.

"Stuart" wrote in message ...
A command button on a sheet presents a form (Frm_Initial) which has a textbox displaying information for the user, plus
Ok and Cancel buttons (where Cancel should exit the routine, and Ok present the next form)....
except that neither button works.

The initial button on the sheet:
Private Sub CommandButton1_Click()
Load Frm_Initial
Frm_Initial.Show
End Sub

and the form code:
Private Sub Cb2_Cancel_Click()
'user clicked Cancel
Unload Frm_Initial
End Sub

Private Sub Cb1_Ok_Click()
'user clicked OK
'Unload Me
Frm_SelectCert.Show
End Sub

What am I doing wrong, please?

Regards.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default Simple Form questions

Many thanks.

Basically, don't unload forms ...............


Q1. when do you? ... Do they need to be unloaded?

Basically, ......control the showing of forms from 1 point.


Q2. Assuming this is not an addin, would you advise one
standard module in the workbook to hold all the
controlling code, rather than sheet code?

Regards and Thanks

"Stevie_mac" wrote in message
...
Add a public Property to your forms called UserAcepted as Boolean
In the Click event for OK, add UserAcepted = True.
Replace Unload Me with Me.Hide
Where your forms are launch the 1st form, do this...

frm_Initial.Show
If frm_Initial.UserAcepted = True then
frm_SelectCert.Show
If frm_SelectCert.UserAcepted = True then
frm_whatever
End If
End If

Basically, don't unload forms & control the showing of forms from 1 point.

"Stuart" wrote in message
...
A command button on a sheet presents a form (Frm_Initial) which has a
textbox displaying information for the user, plus Ok and Cancel buttons
(where Cancel should exit the routine, and Ok present the next form)....
except that neither button works.

The initial button on the sheet:
Private Sub CommandButton1_Click()
Load Frm_Initial
Frm_Initial.Show
End Sub

and the form code:
Private Sub Cb2_Cancel_Click()
'user clicked Cancel
Unload Frm_Initial
End Sub

Private Sub Cb1_Ok_Click()
'user clicked OK
'Unload Me
Frm_SelectCert.Show
End Sub

What am I doing wrong, please?

Regards.






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Simple Form questions

Q2. Assuming this is not an addin, would you advise one
standard module in the workbook to hold all the controlling code, rather than sheet code?


It depends on what you are doing. But personally, I like to have a Module named "Main" that does the overall control &
aptly named modules or classes of routines that perform related functions (or just 1 module called Aux if working on
smallish project)

Sometimes on very small projects where just a quick routine is required, I'll leave it in the sheet (no modules).

Sometimes, you must have code in a sheet (event handlers for example), but if the functions performed can be
parameterised & will be used in other functions or sheets, put that in a module or class. That way, if a problem exists
in your code, you only make the correction in one place.
Don't repeat the same code, parameterise it in a function, or build a class (if appropriate)
e.g.

...::Sheet Code::..
Private Sub UpdateCol_A
Aux.UpdateCol("A")
End Sub
Private Sub UpdateCol_B
Aux.UpdateCol("B")
End Sub

...::Module Aux ::..
Public Sub UpdateCol(col as String)
'Lots of stuff...
'Lots of formatting...
'Lots of clever things... '***Some problem here fixed.***
'Lots of calculations...
End Sub


Q1. when do you? ... Do they need to be unloaded?


You can (if you wish) unload forms when you are finished e.g.

frm_Initial.Show
If frm_Initial.UserAcepted = True then
frm_SelectCert.Show
If frm_SelectCert.UserAcepted = True then
frm_whatever
End If
End If

Unload frm_Initial
Unload frm_SelectCert
Unload frm_whatever

But is it even necessary? VB will clean up when excel is closed.
Its not like the forms you are loading will hold MB's of data in variables - are they?

It is kind of a judgement call, perhaps your forms loads data from a file - or DB. Perhaps it takes 5 seconds to load
that. Would you want to have that happen everytime the form is to be shown? I wouldn't, I'd simply hide the form.

If the forms are for input & you don't clear them explicitly (ie Textbox1.Text = "": List1.Clear etc) then when they
are shown again, they will hold the old input data. Now this sometimes is a bonus & other times a pain!

If the forms are quick loading & must be cleared, Unload them after use!

From the info above, you should be able to make your own judgement

Regards - Steve.

"Stuart" wrote in message ...
Many thanks.

Basically, don't unload forms ...............



Basically, ......control the showing of forms from 1 point.


Q2. Assuming this is not an addin, would you advise one
standard module in the workbook to hold all the controlling code, rather than sheet code?

Regards and Thanks

"Stevie_mac" wrote in message ...
Add a public Property to your forms called UserAcepted as Boolean
In the Click event for OK, add UserAcepted = True.
Replace Unload Me with Me.Hide
Where your forms are launch the 1st form, do this...

frm_Initial.Show
If frm_Initial.UserAcepted = True then
frm_SelectCert.Show
If frm_SelectCert.UserAcepted = True then
frm_whatever
End If
End If

Basically, don't unload forms & control the showing of forms from 1 point.

"Stuart" wrote in message ...
A command button on a sheet presents a form (Frm_Initial) which has a textbox displaying information for the user,
plus Ok and Cancel buttons (where Cancel should exit the routine, and Ok present the next form)....
except that neither button works.

The initial button on the sheet:
Private Sub CommandButton1_Click()
Load Frm_Initial
Frm_Initial.Show
End Sub

and the form code:
Private Sub Cb2_Cancel_Click()
'user clicked Cancel
Unload Frm_Initial
End Sub

Private Sub Cb1_Ok_Click()
'user clicked OK
'Unload Me
Frm_SelectCert.Show
End Sub

What am I doing wrong, please?

Regards.








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default Simple Form questions

Thanks for the advice and examples.
Clearer now.

Regards.

"Stevie_mac" wrote in message
...
Q2. Assuming this is not an addin, would you advise one
standard module in the workbook to hold all the controlling code,
rather than sheet code?


It depends on what you are doing. But personally, I like to have a Module
named "Main" that does the overall control & aptly named modules or
classes of routines that perform related functions (or just 1 module
called Aux if working on smallish project)

Sometimes on very small projects where just a quick routine is required,
I'll leave it in the sheet (no modules).

Sometimes, you must have code in a sheet (event handlers for example), but
if the functions performed can be parameterised & will be used in other
functions or sheets, put that in a module or class. That way, if a problem
exists in your code, you only make the correction in one place.
Don't repeat the same code, parameterise it in a function, or build a
class (if appropriate)
e.g.

..::Sheet Code::..
Private Sub UpdateCol_A
Aux.UpdateCol("A")
End Sub
Private Sub UpdateCol_B
Aux.UpdateCol("B")
End Sub

..::Module Aux ::..
Public Sub UpdateCol(col as String)
'Lots of stuff...
'Lots of formatting...
'Lots of clever things... '***Some problem here fixed.***
'Lots of calculations...
End Sub


Q1. when do you? ... Do they need to be unloaded?


You can (if you wish) unload forms when you are finished e.g.

frm_Initial.Show
If frm_Initial.UserAcepted = True then
frm_SelectCert.Show
If frm_SelectCert.UserAcepted = True then
frm_whatever
End If
End If

Unload frm_Initial
Unload frm_SelectCert
Unload frm_whatever

But is it even necessary? VB will clean up when excel is closed.
Its not like the forms you are loading will hold MB's of data in
variables - are they?

It is kind of a judgement call, perhaps your forms loads data from a
file - or DB. Perhaps it takes 5 seconds to load that. Would you want to
have that happen everytime the form is to be shown? I wouldn't, I'd
simply hide the form.

If the forms are for input & you don't clear them explicitly (ie
Textbox1.Text = "": List1.Clear etc) then when they are shown again, they
will hold the old input data. Now this sometimes is a bonus & other times
a pain!

If the forms are quick loading & must be cleared, Unload them after use!

From the info above, you should be able to make your own judgement

Regards - Steve.

"Stuart" wrote in message
...
Many thanks.

Basically, don't unload forms ...............



Basically, ......control the showing of forms from 1 point.


Q2. Assuming this is not an addin, would you advise one
standard module in the workbook to hold all the controlling code,
rather than sheet code?

Regards and Thanks

"Stevie_mac" wrote in message
...
Add a public Property to your forms called UserAcepted as Boolean
In the Click event for OK, add UserAcepted = True.
Replace Unload Me with Me.Hide
Where your forms are launch the 1st form, do this...

frm_Initial.Show
If frm_Initial.UserAcepted = True then
frm_SelectCert.Show
If frm_SelectCert.UserAcepted = True then
frm_whatever
End If
End If

Basically, don't unload forms & control the showing of forms from 1
point.

"Stuart" wrote in message
...
A command button on a sheet presents a form (Frm_Initial) which has a
textbox displaying information for the user, plus Ok and Cancel buttons
(where Cancel should exit the routine, and Ok present the next form)....
except that neither button works.

The initial button on the sheet:
Private Sub CommandButton1_Click()
Load Frm_Initial
Frm_Initial.Show
End Sub

and the form code:
Private Sub Cb2_Cancel_Click()
'user clicked Cancel
Unload Frm_Initial
End Sub

Private Sub Cb1_Ok_Click()
'user clicked OK
'Unload Me
Frm_SelectCert.Show
End Sub

What am I doing wrong, please?

Regards.










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
Questions should be simple please help babiigirl Excel Worksheet Functions 3 June 14th 06 07:24 PM
Further simple Form questions Stuart[_21_] Excel Programming 8 March 12th 05 06:05 PM
Simple Questions James[_17_] Excel Programming 3 December 7th 03 04:22 PM
Several simple questions Stuart[_5_] Excel Programming 1 September 14th 03 08:58 PM
Simple VB and Excel questions Kevin Excel Programming 1 August 5th 03 08:40 PM


All times are GMT +1. The time now is 01:00 AM.

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

About Us

"It's about Microsoft Excel"