UserForm_Activate & _Initialise will not Run

krissz

Board Regular
Joined
Feb 21, 2010
Messages
95
I am adding a UserForm to speed data entry for our test engineers. This has 3 pairs of TextBox & SpinButtons for selection of product & test plus the test result. Also an Exit button & 2 labels.
_Initialise & _Activate is supposed to set the text for the TextBoxes plus values for the SpinButtons, default or otherwise.
Neither will run. Have tried location the procedures under Forms & the applicale Sheet, but no avail.
Have now stripped out all the code apart from Message Boxes & some text to try & debug.

What is preventing the routines from running ?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Welcome to the board.


Initialization code would go in the UserForm.
In VBA, right click your UserForm, choose "View Code".
Paste your code there.

You say your code does not run. Are you getting any errors?
Please post your code if you need help with it.
 
Upvote 0
Thanks.
The code is in Forms.

In the Sheet, I have:
Code:
Option Explicit

Private Sub Show_Ent_Win_Click()
 ' Open Data Entry Box
         
    Load Data_Entry
    Data_Entry.Show
    
   Unload Data_Entry

End Sub
In Forms, I have:

Code:
[INDENT]Option Explicit

Public Test_No As Integer
Public Meter_No As Integer

Private Sub DE_Close_Button1_Click()
' Close the Entry Box
    
   Worksheets("Reference").Range("C202").Value = Meter_No
   Worksheets("Reference").Range("C203").Value = Test_No
   
    Data_Entry.Hide
 

End Sub

Sub Data_Entry_Initialise()
    
 MsgBox "Initialising"
    
    Meter_No = Worksheets("Reference").Range("C202").Value
    Test_No = Worksheets("Reference").Range("C203").Value
        
    TextBox_Reading.Text = "Run"

End Sub

Sub Data_Entry_Activate()

 MsgBox "Activating "
   
    If TextBox_Reading.Text = "" Then
        Data_Entry_Initialise
        TextBox_Reading.Text = "Init'ed"
    Else
        TextBox_Reading.Text = "Not Run"
    End If

End Sub
[/INDENT]
None of the message boxes appear.

Whether important, I do not know, but I first started with default names for all the boxes & controls; then renamed them.
 
Upvote 0
Change your Initialise entry line from:
Code:
Sub Data_Entry_Initialise()
To:
Code:
Private Sub UserForm_Initialize()
 
Upvote 0
John
Thank you. I expected the commands to be specific to the form. Have also changes the _Activate & that now works. Also, I note that I had to change the spelling if Initialise to Initialize to make it work.

I presume that if I have several Userforms, the code will be located within each module & be localised that way.

The next fun will be transferring data between the various modules - gave up on this & am using part of a excel sheet. There appears to be no truly Global Variables - as I understand the Global simply means that the definition is valid within the Sheet, Form, etc.

Thanks again
Kris
 
Upvote 0
Why are you using Activate and Initialiaze?:)
 
Upvote 0
Kris

Welcome to Mr Excel!

Just an aside...............

A quick way to get to the correct place to place your code, with may of the objects, is to right_click them and select "View code." This goes for the userforms too. If you do this with a userform at design time, all you have to do is select the event you wish to use, from the right-hand drop down at the top of the VBA pane, and the event holder is there for you, pre-loaded, which takes away a lot of the frustration, and spelling errors etc! Same for spinners, commandButtons etc - well, at least the ActiveX ones.

As for Global Variables - if you declare them at the TOP of a module, then they are truly global....... so
Code:
 Public Kris As String

.......at the top of any module will create a place in memory.

To give the variable a value from ANYWHERE in your workbook / project...

Code:
Sub set_Kris()
Kris = "Testing Kris"
End Sub

To test the variable a value from ANYWHERE in your workbook / project...
Code:
Sub check_Kris()
MsgBox Kris
End Sub
 
Upvote 0
Norie
To set the variables in the box. Data entered via the box will be put into the main sheet.
It is a lot quicker for the operator to centralise all data entry into the one box rather than moving around the sheet. Also reduces the possibility of errors as the potential entries will be limited.
 
Upvote 0
Sykes
Thank you ! I am rather far down the line with this, having set up a sheet area for variable storage, but will certainly use it in future.
I am just moving into VBA, most of my cosing was on databases with a very different (& flexible) coding structure. Also minimal help except for books.
Kris
 
Upvote 0
So why are you using Activate and Initialize?:)
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top