Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Form Activate And Initialize


What is the difference between Form initialize and form Activate? When I say form Form1.Show() which of the events trigger?

Here is the problem I have. When ever I say Form.Show() I want the program to do some stuff. Right now I have all that code in Form_Activate. I also have a modal form that I open on and off on top of the other form. But every time I close the modal form Form_Active triggers. So I want to put the code that’s in Form_Activate some where else so whenever I say Form.Show() it will run that code. I already tried form load and it doesn’t work.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Form Initialize Vs. Form Load Vs Form Activate
I'm sure this is one of the most basic of questions in terms of VB, but I've been working with VB for 4 months now, and have yet to realize the differences between form initialize and form load and form activate.

Can some please clairify, thanks.

Load, Initialize, Activate...
I don't understand the difference between the Load, Initialize, and Activate events in a form as well as Unload, Terminate, and Deactivate. What's the order and why are there so many different events?

Thanks a lot

Form Does Not Initialize
Okay, my form (with textboxes) is filled with data from the active document. The following shows what problem I am having:
1. User runs macro which opens a document called "2001.xls" then executes dataForm.Show
1. User hits Done_Click which executes Unload Me
2. User closes active document (basic close) but doesn't close Excel.
3. User runs macro which opens another document called "2002.xls" then executes dataForm.Show
Problem
3. Form contains data from the previous document called 2001.xls.

This happens when I use Unload Me or just dataForm.Hide
The problem, I believe, is that the second time the macro is run and dataForm.Show is executed, the form does not initialize (UserForm_Initialize).

Any thoughts?
Aaron

Form Initialize
I load and unload a form. The first time the form gets initialized but after that it doesn't. I have code in the form_initialized
event that needs to run each time the form is run. Unloading the form doesn't seem to be enough. What am I missing? Can anyone tell me what I should be using instead of Unload? Thanks

Unloading Form From Form's Initialize Event
Hello,

I have the following code:


Code:
Private Sub UserForm_Initialize()

Dim AddInsListBox As MyListBox
Dim TitleListBox As MyListBox
Dim UserAddIns As myAddIns
Dim ConfigFile As INIFile

Set ConfigFile = New INIFile
Set UserAddIns = New myAddIns
Set TitleListBox = New MyListBox
Set AddInsListBox = New MyListBox

ConfigFile.Path = ThisDocument.Path & "" & INI_FILE_NAME

On Error GoTo ErrIniAddInsPathNotFound
UserAddIns.AddItemsInFolder ConfigFile.Sections.Item _
(INI_MAIN_SECTION).Keys.Item(INI_KEY_ADDINS_PATH).KeyValue
On Error GoTo 0

Set AddInsListBox.AListBox = Me.lstAddInList
Set TitleListBox.AListBox = Me.lstTitle

TitleListBox.AddRowToList "Complemento", "Instalado"
AddInsListBox.AddRowsToList UserAddIns.BasicInfoToArray("Sí", "No")
AddInsListBox.SelectItemsInList UserAddIns

' AddInsListBox.ResizeListBox LISTBOX_HEIGHT

Set UserAddIns = Nothing
Set TitleListBox = Nothing
Set AddInsListBox = Nothing

Exit Sub
ErrIniAddInsPathNotFound:
MsgBox "No se encuentra la ruta a los complementos."

Dim NewPathToAddIns As String

NewPathToAddIns = UserFolderSelect

If Not NewPathToAddIns = vbNullString Then

ConfigFile.AppendSection INI_MAIN_SECTION
ConfigFile.AppendKeyToSection _
INI_MAIN_SECTION, INI_KEY_ADDINS_PATH, NewPathToAddIns
ConfigFile.WriteMemoryToINI

'vuelve a la línea de código errónea
Resume
Else
Set UserAddIns = Nothing
Set TitleListBox = Nothing
Set AddInsListBox = Nothing

Unload Me ' <<< Offending line: Error 91
End If
End Sub

I'm trying to unload the form (in Word) if the user cancels a folder selection dialog. This operation is done in the error handling routine and it somehow raises an error I can't figure out. Has anyone a clue?

Regards,

Guillermo

Form Initialize Event
I have a few lines of code in the _Initialize event that I can't put in the Load event because of, among other, some late-binding objects in the form.

It works fine in the _Init.. event but that event fires every time the form looses then regains focus. This is the source of a bug that I've been tracking down for a few days and now I need to remedy it.

I thought about creating a Boolean variable with form level scope that I can use to determine if this is the first time the code has been ran, and I'm sure this will work, but I was just curious what all of you would do in this case. I know this is a common problem and I'm sure you've had to come up with a solution sometime, so let's hear it!

I did a quick check to see if the code will work in the _Activate event but that's a no-go as well

Also, I *really* hate it when I see code where people rig up a timer in the form_load to do this--so i don't even consider this and similar hacks to be viable solutions.

Thanks for your input.

Shane

Next Question......what Is Form.Initialize?
I was wondering what Form.Initialize is used for? Is it run before Form.Load?

Thanks

Form Initialize Error Trap
All,

I've a vb6 Windows app that has a form that I know will throw a Microsoft canned error ("There was an error executing the command") if a user tries to open the form and the workstation doesn't have the proper .dll's and .ocx's loaded on his/her workstation. This is fine, but I'd rather trap the error and present the user with a customized error message.

However, I've been unable to trap the error. I've added an 'on error' line in the form.initialize event and in the form.load event, but the Microsoft canned error still comes up. Any help will be greatly appreciated. Here's the code I've added to my form.initialize event:

Private Sub Form_Initialize()
On Error GoTo end1
Exit Sub
end1:

Dim str1 As String
str1 = "This workstation does not have the required installed components (either ABI or Thermo) to open this module."
MsgBox str1, vbCritical, "Invalid action..."

Unload Me

End Sub

Initialize Default Values Of Widgets On Form
I have a few widgets on my form. I was wondering if VB6.0 has any feature equivalet to what init() in java. Java uses init() to intilialize the widgets when the program is run. I have a few radiobuttons and i would like to set their intial values so that one of them is checked when the user sees the screen for the first time. In java i just use the init() function/method but i am not sure how to do that in VB. Could someone plesase let me know. thanks.

Form Initialize Vs Form Load ?
So whats the difference between these 2?

How To Make Form Activate By Clicking On TitleBar Of Form?
Hello Everyone....

In MDI Application, I have want to make child form activate by clicking on it's title Bar.

Also,

Want tot make MDI appliction activate by clicking on it's titlebar when switch from another app. such as MS Excel to my App.

HOw????

Thanks.

HDave

Difference Between Form Load And Form Activate?
Hi guys,
Anybody knows whats the difference between form load and form activate..


Regards,
1g0r

Activate Form
hi people...

i'm with a problem here...

ok, let's start...
my app is already showing on the systray, (that's nice), that's ok...
when i "close" the app clicking on the X on the window, it just hides the window, so i can show it again clicking on the SysTray...

if u try to open the EXE again... my "Sub Main" detects that my app is already loaded, and stops the proccess...

that's alright, but, i wanted that when people try to open the EXE again (if the app is already in the systray) it just shows my form (frmMain) again...

understood ? is there anyway to do it ?

i tried this:

Code:
Sub Main()
If App.PrevInstance = True Then
Dim lRet As Long

lRet = FindWindow("ThunderFormDC", "My Main Form")
'Here it's ok, it finds the window...
SendMessage lRet, WM_SHOWWINDOW, 0, 0
'But don't show =(

'Now END this proccess and let the other still open...
End
End If
'If didn´t find any proccess, so load frmMain...
frmMain.Show
End Sub

Activate Form
I want to show a form on every other apps after 15 mins to attention user. How to do it

Activate Form
Hello;
I'm working with Mdiform, but there are also independent forms under my project. Regarding to my problem , i can open new independent form from MdiChildform meanwhile i have some code under mdiChildform activate event. When user close to independent form, i want to work code which on mdichildform activate event.
I tried to refresh MdiChildForm but it doesn't work
How can i do this?
Thanks

Form Activate
is there code where you can find out which form is activated or not....also how do you get all your forms from starting up when played

Form Activate
One for the guru's i think:
I have this:

Dim index As Integer
If loadedcheck = False Then
For index = 0 To 5
If index <> 0 Then
Load CheckGDW(index)
CheckGDW(index).Top = CheckGDW(index).Height * index + CheckGDW(index).Top
End If
CheckGDW(index).Visible = True
CheckGDW(index).Caption = "Check box number " & index
Next index
loadedcheck = True
End If

...you experts will note that this creates check boxes to the amount specified, what i would like to do is read a mdb file and create the amount of check boxes to the specific text from the mdb file for instance:

loop until eof
txtCustomerID = "" & rs!CustomerID
end

Many thanks in advance

How Do I Activate Sheet While In A Form?
Asking again for help opn my first attempts to use forms ...

Is it possible to have a form visible and still allowing user interact with the sheet?


Code:
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim r As Range
If TextBox2.Text <> "" Then
Set r = Range("B:B").Find(TextBox2.Text)
If Not r Is Nothing Then
If r.Row Mod 2 = 0 Then
r.Offset(0, 1).Select
Else
Range(r.Offset(0, 1), r.Offset(-1, 1)).Select
r.Offset(0, 1).Activate
End If
End If
End If
End Sub
After text is entered, I would my users to be able to enter text on the selected cell and interacting with excell without closing the form. The same behaviour as a standard Find/Replace form.

The form is activated through a UserForm1.Show statement. Should I use any modal value? vbModal/vbModeless does not seem to make any difference .

Thanks in advance.

Form Activate Problem
Hello - sorry to post on a Friday afternoon!

I have placed a breakpoint within a form_activate sub. However, when the the form is loaded and interacted with, I cannot get the breakpoint to work. Surely when the form is loaded, triggered, used in any way this sub should be activated? Or am I missing something obvious here?

It is as if this section of code is not even processed(?)

Form Activate Event
I don't get Form Activate events (or Deactivate, Got/lost Focus events) when I swap to/from my VB6 app from another app. I should, shouldn't I!

Put a long, multiline label and a command button on a form
Put this in the form's code

Private Sub Form_Load()
Label1 = "Load"
End Sub

Private Sub Form_Initialize()
Label1 = Label1 & vbCrLf & "Initialize"
End Sub

Private Sub Form_Activate()
Label1 = Label1 & vbCrLf & "Activate"
End Sub

Private Sub Form_GotFocus()
Label1 = Label1 & vbCrLf & "Got Focus"
End Sub

Private Sub Form_Deactivate()
Label1 = Label1 & vbCrLf & "Deactivate"
End Sub

Private Sub Form_LostFocus()
Label1 = Label1 & vbCrLf & "Lost Focus"
End Sub

Private Sub Command1_Click()
Label1 = Label1 & vbCrLf & "Click"
End Sub



Run and click some other app and then back to the form..

Form Activate Event
Hi,

I have a form where I store data to access db. After that I close the first form and open a second form (with vbmodal), where I try to read the data with data controller. But the data just isn't there. The problem is this (at least my guess is this) When the second form opens and the data controller tries to read from access db, the access table is not saved yet. I have also tried to refresh the data controller in form activate event, but it's not the solution because this form was in modal mode and the form activate event does not occur.

Can anyone tell how to solve this problem?

Activate Form **Resolved
In my app I have set the form to be (1) on top at all time, (2) and transparent as well. Now I have a question.

How can I get the form to react if the mouse is passed over it?

TIA,

Activate Form By HWnd
I am writing an app where I have multiple instances of the same form.
When a new form is activated I save the hWnd value of the form and later in the program I need to send data to the form.

since there are multiple forms I check (for example for) the name. when I find the name then I search for the appropriate hWnd value. once that is found I need to activate the form with that hWnd value and parse the data to it.

How can I activate a form with its hWnd value ?

thanks

Form Activate And Load Sub
Have you tried putting a Stop at the top of your procedure, and using F8, walk through your code to see exactly what is happening?

Help Activate A Module From A Form.
Hey,

This is the situation, I have an app that sits in the systray. When the user left clicks on the icon I want a module to be activated. How do I do it?

(I already have all of the code for my app! All I need is to know the syntax for activating the module. I keep getting an error saying, "expected variable or procedure not module.")

Can anyone help me?


------------------
Thanks,
MiDaWe

Help Activate A Module From A Form.
Hey,

This is the situation, I have an app that sits in the systray. When the user left clicks on the icon I want a module to be activated. How do I do it?

(I already have all of the code for my app! All I need is to know the syntax for activating the module. I keep getting an error saying, "expected variable or procedure not module.")

Can anyone help me?


------------------
Thanks,
MiDaWe

Activate A Form From One Application To The Other
i have a form1 in one application1 (Active exe) and form2 in
another application2. i am refereing application1 from
application2. Now my problem is, one button is there
in form2 and iam clicking the button and it will call the form1
in application1. but the form1 is opening behind the form2. i
need to bring front (this part i did). but if i bring the form1
in front its not active, still form2 only active. I want to make
form1 active.

Form Activate Event
I have a code which pastes a large amount of information cell by cell from one excel sheet to another which takes a lot of time .I want to hide the process going on by putting a form in front with an animated gif in it.Please help.I tried with a form with lot of control on it and put my code in the form activate event but while processing the code,the form appears white and no control i diplayed.I don't know why .May be because the multitasking has been too much for my PC.Anyway I have deleted all control from the form and is planning to put animated gif.

This Is So Annoying (Form Load/Activate)
Is it just me or is VB missing a critical event: One that triggers when the form loads and appears, but not each time it gets the focus back like the Activate event.

To get around this I always put a 1 ms timer on each form where I need this sort of event that executes code and disables itself immediately.

I can't beleive there isnt a better way of doing this, I could use the Activate event with a boolean to see if its the first activate since the load but thats not much better.

Why isnt there an event for this built in?!?!

Timer Activate When I Load Form
So i made a cheat for my game, when i press I + L + M then i get more score but then i cant win the game, but my problem is when i open form then a msgbox will come saying that i cheat(i made it when i press I + L + M) but i didnt press I + L + M yet

How To Trigger Activate Event Of A Form?
I have 2 exe programs.
prg1.exe = calling program
prg2.exe = program to be called

prg1 code to call prg2:

VB Code:
' Specifying vbNormalFocus as the second argument opens the application in ' normal size and gives it the focus.Dim RetValRetVal = Shell("C:WINDOWSprg.EXE 0001", vbNormalFocus)   ' Run prg2.  


prg2 code to unload, back to prg1:

VB Code:
'there is some others code before Unload Me'Function WriteInfoToINIFile()Unload Me


Requirements:
After prg2 Unload, the prg1 back its previous state and need to change some data depends on the written data from INI File by the prg2 upon the prg1 activate the program.

Problem:
The Activate event of prg1 is not triggered upon activation.

Conclusion:
The Activate event occurs when an object becomes the active window. But moving the focus to or from an object in another application doesn't trigger either event.

Favors to the group:
1) Please give a hints on how to trigger activate event switching between 2 applications.
2) If you have other way to meet the requirements, much better. Please teach me.
3) Also upon calling the prg2, the user should not able access prg1. Its like with calling other form using Show method with vbModal. But it is within the application.. How about between two applications. (maybe Hiding the prg1 first before calling the prg2 then show it again after prg2 unload.

Thank you very much.

Form Activate/Load/GotFocus
I'm trying to have a function run IMMEDIATELY after a form is opened. Generally, I'd put a "CALL" to the function into the FORM_LOAD event, but my problem is that the form isn't being displayed and the function is already being called.

I've tried adding the "sleep" function, and even moving my function into the activate or got focus events, but they all do the same thing.

Essentially, I need the user to see the text on this form, PRIOR to have the function running... BUT i need the function to start soon after the text is displayed, say, 2 seconds later?

Does this make sense?

Toolbar Disappears After Form Activate
I added a toolbar to my app at the very end of development. Here's what happens: when the form is activated and while the form loads a listbox the toolbar and all buttons are visible, but as soon as the listbox is fully populated the buttons go invisible. I can click on where the buttons are on the form then they become visible, OR when I step through the program at the end of stepping the buttons remain visible, but when the program runs normally they turn invisible. I have checked all properties on the toolbar and buttons and they are all enabled and visible. The toolbar iteslf does not turn invisble, only the buttons.
I have tried forcing the buttons visible as the last line of code but it still doesn't work.

Can anyone point me in the right direction to solve this?

Form Activate Event Not Firing
Well I'm facing a very peculiar problem with my MDI app. When the application starts the first time and I invoke any MDI child, the activate event of that MDI child does not fire. However, if I again reopen that MDI child or any other MDI child, the respective activate event starts firing. Can anyone explain this problem?

Form Activate Vs Form Form Load?
Hi all,
sorry to trouble u again with my problem. well as the subject header this thread stated. i would like to know what is the different between Form_Activate and Form_Load in VB .. or in fact i am using eVB now. well, i guess it shouldnt make much of a different for this problem. appreciate your kind comment and help.

longwar

Form Activate Fires Before Load Finishes
How is it possible for a forms Activate event to fire before the Load is completed?

Confused.

How To Activate An Event Of A Form In A Function **Resolved**
Hi all,
I have a function. In this function I would like to call a form. the form has a text box and a command button.

The doubt is how to actuate the event procedure of a command button in the called form with in the function.

Activate A Hidden Form From Aanother Program
Ive written 2 programs.....one hides itself......Is it possible for the second program to activate (show) the first program when its been hidden. Appactivate("Form1") work great if the form is behind another window but if its been hidden, it gives a runtime error 5

Problem With Form Load/Activate Events
Follow up to a post i made last week and desperately need help with (as it gos to the customer tomorrow for testing!):

When i step through line by line in debug environment my form.load event is processed but not my form.activate. When i run it straight off, the other way round happens.

so how can i ensure that the form.load event has taken place before the form.activate event kicks off? just use a flag and test?

all suggestions greatfully appreciated!
Kester

What Would Prevent A Form&#039;s Activate Event From Firing?
I have inhereted a MDI app here where I am observing strange behavior with a form. One child form (let's call it Form1) calls the Show method for another child form (let's call it Form2).
When Form2.Show is executed, the Load event for Form2 occurs, but the Activate event for Form2 does NOT fire as expected. The result is a partially visible Form2 (with controls missing, etc.) with Form1 behind it. If I click on Form1, then click back to Form2, Form2's Activate event fires and the program proceeds normally. I have coded a work-around that works, but I'm puzzled as what is going on.

My work-around code is:
(In Form1)
Form2.Show
Form1.SetFocus
Form2.SetFocus

Any ideas?

Menu Bar Hidden When Child Form Activate ???
Hi everyone!

I have a mdi form with 2 children form. I put a menu bar in my mdi form. One of the 2 children form (always the second form) when clicked hide the menu bar and reappear when the first child form is clicked. Why???

Thanks in advance!

Activate Form With Calander8-activex Cause Error
when i try to run a form with active-x calander 8.0 ctrl,
im getting a massege sais :
"MSaccess cause an error in vba332me.dll"
then MSaccess shutdown .
what on earth is that?
pls,pls, with it my all work is gone!
jack.

Command On Form To Auto Activate And Send An Email
created a Form in Word.
created a checkbox, if clicked attaches document to a new email message "active

Activate / Jump To Form Record Based On Field Data...
From my main form (Me), I would like to go to another subform called...

frmSubAssyLIstingSubform

and go to the record wth the field SubAssy (also the control name on the subform), whose value is found in

Me!frmBOMSubform.Form!txtSubAssy3

For example, lets say the value for my SubAssy is 102. This is contained in a textbox on frmBOMSubForm.

Upon refreshing this information, the frmSubAssyListinfSubform starts over at the beginning. This is done because other factors are dependant on any new information entered in the database. I would like to page to the last SubAssy used, which is contained in my Textbox.

I've tried a few things... Presently, this is what my code looks like. I am unsure how to get the form to jump to the record.



Private Sub Form_Activate()
DoCmd.SelectObject acForm, "frmMain", True
DoCmd.Maximize

Me.Refresh

If Len(Me!frmBOMSubform.Form!txtSubAssy3) & "" > 0 Then
Me!frmSubAssyListingSubform.Form.SetFocus
Me!frmSubAssyListingSubform.Form!SubAssy.SetFocus
DoCmd.FindRecord Me!frmBOMSubform.Form!txtSubAssy3, acEntire
End If

Thanks in advance for any help you can provide...

How To Avoid Controls Click Events In Form Activate Event...
Hi,
Is there any way to avoid the click event send that automatically Activate form event sends to all controls in the form???

Thanx in advance !!!!

Activate, Ye Stubborn Cell! ACTIVATE I SAY!!!
I'm glad to have one of my trademark needlessly complicated issues to present to you all. In my form is a combo box ('EventMenu'), two text boxes ('AskIt' and 'Moofus') and a button. Nice users will enter a string into the 'AskIt' box and my program will find the cell (all I really want is the row) where that string is found. Users also will have entered text into 'Moofus'; and this text will be entered into a cell on whichever row the AskIt string was found. Which cell, you ask; for there are many. Which cell the Moofus string ends up in depends on what the user selected from the EventMenu combo box.

Here is the script for when the button clicks:

Code:
Private Sub Findit_Click()
Loogit = Askit.Value
Hepcat = Moofus.Value
Set C = Worksheets(1).Cells.Find(Loogit, LookIn:=xlValues)
Showit.Value = C.Row
If EventMenu.SelText = "ONSITE" Then Cells(C.Row, 13).Activate
If EventMenu.SelText = "STARTUP" Then Cells(C.Row, 14).Activate
If EventMenu.SelText = "LOAD" Then Cells(C.Row, 15).Activate
If EventMenu.SelText = "MKEY" Then Cells(C.Row, 16).Activate
If EventMenu.SelText = "PROD" Then Cells(C.Row, 17).Activate
ActiveCell.Font.Bold = False
ActiveCell.Font.Size = 10
ActiveCell.Value = Hepcat
End Sub

In my dream world, they enter 1234A into AskIt and the program finds 1234A on row 11; the user selected "MKEY" from the Menu and thus the cell at R11C16 is activated and populated with Moofus.Value.

But all that happens instead is that the Moofus.Value ends up in whichever cell was active when I ran the macro.

Wha happened?

When You Should Initialize...
in vb6, when do you think it is best to initialize the values of objects such as size, fonts, colors, etc etc of forms, buttons, frames and etc? should it be initialize in the properties menu or using coding to initialize it? or during the run-time? can anyone tell me what's the difference anyway and which one is better?

How To Run Initialize Again?
How can i force a especific form to run initiazile again evertime i use the "form.show", or maybe the trick relies on the way i close the form?

I think it's because of the "form.hide" am using, it justs hides it but it remains resident in memory so the initialize will not run... well that's my theory?

tks 4 ur attention and possibel help!

Cannot Initialize OLE
Hi

Our appln is in VB and uses Crystal Reports 7 and database is MS ACESS. Everything was working fine in our organization. Now when our clients tries to pull any report, it throws "Cannot Initialize OLE".After clicking OK its again throwing "Error 20534 - Error detected by database dll" error message.
But it works fine for us here.

Any idea how to rectify it...

Your help is much appreciated.

Thanks in advance

Copyright © 2005-08 www.BigResource.com, All rights reserved