Understanding Forms and form events


Written By TheVBProgramer.

The Show and Hide Methods


The Show method of a form displays that form on the screen. If the form to be shown is not already loaded into memory, the Show method will load it before showing it. The Show method is typically used to transfer control from one form to another. The syntax is:




For example, if I am in Form1 and I want to display Form2, the syntax would be:




When you display one form from another, you may want the user to complete work on that form before returning to the first one. This does not happen automatically. By default, VB will display the second form and then continue executing code from the first form. To suspend execution of the first form until after the second form is done with, add the keyword constant vbModal as an argument to the Show method. The syntax is:


Form2.Show vbModal


The Hide method of a form removes the form from the screen (makes it invisible), but the form still remains in memory. The syntax is:




To refer to the form in which code is currently running (i.e. the "current" form, or the "active" form), you can of course refer to the form by its name, as in the example above:




As an alternative, you can use the keyword Me. The keyword "Me" refers to the form in which code is currently running:




Finally, any time you want to execute a method of the form on itself, you can simply code the method name, omitting the "formname." or the "Me.", as in:





The Load and Unload Statements


The Load statement loads a form into memory, but does not display it. When you code the Load statement for a form, the Form_Load event of that form will be triggered. The syntax is:


Load formname


The Unload statement removes a form from memory and from the screen. When you code the Unload statement for a form, the Form_Unload event of that form will be triggered. The syntax is:


Unload formname


A form can unload itself, as in:


Unload Me


The Unload event is also triggered with the user clicks the Windows "close" button ("X") on the form.


Try this:

·         Place a command button named "cmdExit" with the caption "Exit" on a form. In the Click event for the command button, instead of coding "End", code:


Private Sub cmdExit_Click()


Unload Me


End Sub


·         For the Form_Unload event, code the following:


Private Sub Form_Unload(Cancel As Integer)


If MsgBox("Are you sure you want to quit?", _

vbYesNo + vbQuestion, _

"Unload Test") = vbNo Then

Cancel = 1

End If


End Sub


·         Run the program and observe what happens either when you click the Exit button, or when you try to close the form by clicking on the "X" button.


Note that VB supplies the Unload event with a built-in argument called "Cancel". If, in the Unload event procedure, you set the Cancel argument to any non-zero value, the Unload event will be cancelled (i.e., the form will not be unloaded) and processing will continue. This event is where you might ask the user if they are sure they want to quit. If they respond Yes, let the Unload event "do its thing"; if No, set Cancel to non-zero value.


Note: When all forms of a VB project are unloaded, the application ends. The End statement automatically unloads all forms in a project, but will not trigger the Unload event (so any code you have in the Unload event will not execute) – therefore, ending an application with "End" does not give the user a second chance to keep working with the program. The End statement ends the program abruptly.


Centering a Form on the Screen


The following code will center a form on the screen. It is best placed in the Form_Load event.


Me.Top = (Screen.Height – Me.Height) / 2

Me.Left = (Screen.Width – Me.Width) / 2


In VB project that has multiple forms, it is a good idea to centralize the form-centering logic in a Public Sub procedure of a separate standard (BAS) module. The sub, which accepts a Form object as a parameter, would look like this:


Public Sub CenterForm(pobjForm As Form)


With pobjForm

.Top = (Screen.Height – .Height) / 2

.Left = (Screen.Width – .Width) / 2

End With


End Sub


With the above Sub in place, any form in the project can center itself with the following line of code:


CenterForm Me


Form_Load vs. Form_Activate


In the Form_Load event, you would typically perform initialization-type tasks, as you should. However, certain types of actions cannot be performed in the Load event, due to the fact that the form is fully loaded only after the Load event completes. For one thing, printing to the form will not work when done in the Load event. In addition, if you try to set focus to a particular control on the form during the Load event, you will get the message Run-time error '5': Invalid procedure call or argument. For example, assume you had a textbox called Text1 on the form. The following code would result in that error:


Private Sub Form_Load()


' other initialization stuff


Text1.SetFocus ' causes an error


End Sub


The reason for the error is that since the form is not fully loaded, neither are any of the controls on it – and you can't set focus to a control that is not yet available.

To remedy this problem, you should use one of the other Form events, such as the Activate event. (When VB loads a form, it actually cycles through a number of events, such as: Initialize, Load, Resize, Activate, GotFocus, and Paint. Of these, Load and Activate are probably the ones most commonly used. ) Placing the code to set focus to a control will work in the Form_Activate event:


Private Sub Form_Activate()


' other statements


Text1.SetFocus ' no problem here


End Sub


A caution about the activate event: it will fire whenever your application switches to that form. For example, if you switch back and forth between Form1 and Form2, be aware that any code you might have in the Activate events for these forms will be executed when you switch to that form. Therefore, if you have code in the Activate event that you only want to execute "the first time", you will need to control execution with a Boolean switch. For example, in the General Declarations of your form you could define the following variable:


Private mblnFormActivated As Boolean ' will be initialized to False by default


You can then use this switch in the Activate event as follows:


Private Sub Form_Activate()


If mblnFormActivated Then Exit Sub


' statements you only want to execute once, including the following

' statement to turn the switch on:


mblnFormActivated = True


End Sub


Multi-Form Projects


Many projects will use more than one form. When you have more than one module (form or standard) in a project, you must specify a "Startup object", which is done via the Project menu, Properties item. The startup object tells VB which form or standard module is to have its code run first (if a standard module is the startup object, it must contain a public subroutine called "Main", and "Sub Main" is specified for the Startup object). By default, the startup object is the initial form that is supplied with every new VB Project.


Here are a couple of scenarios for projects with multiple forms:


(1)                 You have an application that performs a variety of functions, requiring multiple "screens" (forms). You can use one form as a "switchboard" or "main menu" form that connects to the other forms.

(2)                 You may wish to have a "splash screen" start off your application before the main form is displayed.


Using Multiple Forms: "Switchboard" Example


Assume you have a project with three forms: Form1, Form2, and Form3. (To add forms to a project, go to the Project menu and select Add Form.) Form1 serves as the switchboard form, which contains three command buttons: cmdForm2, cmdForm3, and cmdExit:





The code behind these buttons is:


Private Sub cmdForm2_Click()

Form2.Show vbModal

End Sub


Private Sub cmdForm3_Click()

Form3.Show vbModal

End Sub


Private Sub cmdExit_Click()

Unload Me

End Sub




For the sake of the example, Form2 and Form3 simply contain one button with the caption "Return to Main Menu". The code behind the command button on each of these forms is simply Unload Me. When either of these forms is unloaded, the main menu form will then become the active form.



Download the VB project code for the example above here.




(Form Procedures)

Presented below is a set of procedures that can be used to work with forms. The code presented can be saved as a .BAS module (for example, modForm.bas) and can be included and used in any VB6 project.


The set of procedures is described below:


Procedure Name




Centers a form on the screen. This Sub has been used in previous examples presented on this site.


Usage: CenterForm FormName

(where FormName is the name of the form without quotes (e.g. Form1) or the keyword Me)


To center the current form, you would use:

CenterForm Me



Function that determines whether or not a form in your app is currently loaded. It does this by searching through the VB Forms collection. It accepts a string parameter containing the name of the form that you want to check and returns a Boolean.


Usage: If FormIsLoaded("Form1") Then ...



Sub that lets you enable or disable the form's "X" (or "Close") button that appears in the right-hand corner of the form's title bar. (A common usage is to disable the X button.) This Sub is a wrapper for a handful of APIs that work together to accomplish this task (GetSystemMenu, GetMenuItemCount, RemoveMenu, DrawMenuBar).


Usage: EnableFormXButton FormName, BooleanValue

(where FormName is the name of the form without quotes (e.g. Form1) or the keyword Me and BooleanValue is True or False)


To disable the X button on Form1, you would use:

EnableFormXButton Form1, False



Sub that lets you keep a form "always on top", even if it does not currently have the focus. This Sub will also let you reverse the action and make the form "not" always on top. This Sub is a wrapper for the SetWindowPos API.


Usage: MakeTopmost FormName, BooleanValue

(where FormName is the name of the form without quotes (e.g. Form1) or the keyword Me and BooleanValue is True or False)


To make the current form "always on top", you would use:

MakeTopmost Me, True


LockWindow /


The purpose of these Subs is help avoid "flicker" when controls and their contents take longer than usual to populate on a form. These Subs are a wrapper for the LockWindowUpdate API, which disables drawing in the given window. Only one window can be locked at a time.


Usage (to lock): LockWindow FormName.hwnd

Usage (to unlock): UnlockWindow


The code is given below:


Option Explicit


Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long

Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long

Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long

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 MF_BYPOSITION As Long = &H400&

Private Const MF_REMOVE As Long = &H1000&

Private Const HWND_TOPMOST As Long = -1

Private Const HWND_NOTOPMOST As Long = -2

Private Const SWP_NOSIZE As Long = &H1

Private Const SWP_NOMOVE As Long = &H2

Private Const SWP_NOACTIVATE As Long = &H10

Private Const SWP_SHOWWINDOW As Long = &H40



' Form-related Routines




Public Sub CenterForm(pobjForm As Form)



With pobjForm

.Top = (Screen.Height - .Height) / 2

.Left = (Screen.Width - .Width) / 2

End With


End Sub



Public Function FormIsLoaded(pstrFormName As String) As Boolean


Dim objForm As Form

For Each objForm In Forms

If objForm.Name = pstrFormName Then

FormIsLoaded = True

Exit Function

End If


FormIsLoaded = False


End Function



Public Sub EnableFormXButton(pobjForm As Form, pblnEnable As Boolean)



Dim lngSysMenuID As Long

Dim lngMenuItemCount As Long

' Get handle To our form's system menu

' (Contains items for Restore, Maximize, Move, Close etc.)

lngSysMenuID = GetSystemMenu(pobjForm.hwnd, pblnEnable)


If lngSysMenuID <> 0 Then

' Get System menu's menu count

lngMenuItemCount = GetMenuItemCount(lngSysMenuID)

If lngMenuItemCount > 0 Then

' Remove (hide) the "Close" item itself (the last menu item) ...

RemoveMenu lngSysMenuID, lngMenuItemCount - 1, MF_BYPOSITION Or MF_REMOVE

' Remove (hide) the seperator bar above the "Close" item

' (the next to last menu item) ...

RemoveMenu lngSysMenuID, lngMenuItemCount - 2, MF_BYPOSITION Or MF_REMOVE

End If

End If

DrawMenuBar pobjForm.hwnd

End Sub



Public Sub LockWindow(hwnd As Long)


LockWindowUpdate hwnd

End Sub



Public Sub UnlockWindow()


LockWindowUpdate 0

End Sub



Public Sub MakeTopmost(pobjForm As Form, pblnMakeTopmost As Boolean)



Dim lngParm As Long

lngParm = IIf(pblnMakeTopmost, HWND_TOPMOST, HWND_NOTOPMOST)

SetWindowPos pobjForm.hwnd, _

lngParm, _

0, _

0, _

0, _

0, _




End Sub



Click here to download a tester project that incorporates this module.


If you enjoyed this post, subscribe for updates (it's free)

random opening of form

I made 5 forms.... one is main form and the other four is sub-forms.... how can i open the four sub-forms randomly with just clicking a button? what code should I use to open it randomly?

random opening of form

Start with a new Standard EXE VB6 project. Form1 will be created automatically. Now add four more forms and leave their names Form2, Form3, Form4 and Form5. Add a command button to Form1. Open Form1 code window and paste the code from below. Forms 2 thru 5 will be displayed randomly with each click of command1.


Private Sub Command1_Click()
Dim mRandNum As Integer
mRandNum = Rnd * 4 + 2
Select Case mRandNum
Case Is = 2
Unload Form3
Unload Form4
Unload Form5
Case Is = 3
Unload Form2
Unload Form4
Unload Form5
Case Is = 4
Unload Form2
Unload Form3
Unload Form5
Case Is = 5
Unload Form2
Unload Form3
Unload Form4
End Select
End Sub

about form1

hey thank you very much.i had got answer of my question which i was finding in many places in this page

closing child form leave line artifact on the parent form

I'm having weird experience with multiple form, not solved yet.

I have 3 forms.
1 main form => opening child form (sales form) => opening child form (search items)
all the child forms containing listview with in frame.

If I call the search items and close the form, it will leave line artifact on the sales form,
the line is black solid horizontal line the same width the search item form width along the frame containing the listview
on the sales form.

How to avoid it? Sometimes it really annoying.

thank you.

set the autoredraw property

set the autoredraw property of the parent form to True


how we can alter the contents of textbox control


Is the locked property set to 'False'? Is the 'enabled' property set to 'True'? What are you really asking?


how to define user defined names in login form that verify wit database in vb coding.. give me syntax for same

window.onbeforeunload =

window.onbeforeunload = function(e) {
// confirm('Are you sure you want to leave?');
if (confirm('Are you sure you want to leave?'))
//else alert('A wise decision!')">

refer from http://www.codeprojectdownload.com


am can you please show the easiest purchasing system and has a inventory ?


Pencil, paper, and cigar box. Simple! Write down what is bought. Put the paper in the cigar box and voila! You have your inventory.

If you want a better answer ask a better question.

about form

how to creating data from one forms and retrieving data from another form Using VB6.0.............pls reply me.......

Implicit Loading -

If I try to access any property of a child form ( still NOT loaded in memory ) from a MDI Form, the child form is automatically loaded into memory.

I wish to access these property WITHOUT the form automatically loading.

Refer to below code.

in the line " If objForm.Name = Myform.name Then", the result is always true because the moment VB engine encounters "Myform.name", it automatically loads this form into memory and returns "True". Thus I am unable to determine if "Myform.name" was loaded in memory before execution of this procedure or not.

"Public Function FormIsLoaded(pstrFormName As String) As Boolean" referred in above snippet fails.


Public Sub CheckFormStatus(Myform As Form)

' This procedure determines if "frm_by_code" is open in the background when
' "frm_by_name" is exited. If yes, it displays "frm_by_code" before exiting.

Dim objForm As Form
Dim FormLoaded As Boolean
Dim FormShown As Boolean
FormLoaded = False
FormShown = False

For Each objForm In VB.Forms

If objForm.Name = Myform.name Then

FormLoaded = True

If objForm.Visible Then

FormShown = True

MsgBox "Load Status: " & FormLoaded & vbCrLf & "Show Status:" & FormShown

' Myform.Show

End If

Exit For

End If


End Sub

Forms collections display info of forms not yet loaded

I have a MDI Form & two Child Forms X & Y.

When MDI Form loads, it does nothing but display a window with two menu options. Clicking first Menu Tab will display Form X & clicking the other Tab will display Form Y.

If i run VB.Forms.count at start of project, it shows 1 form is loaded ( the MDI form ).

Now if I click Menu Tab "X", Form X loads.

Now vb.forms.count shows 2 forms are loaded ( MDI form & Form X ).

Now I exit Form X by issuing "unload me" command, the form disappears and control returns to MDI application.

Then I click Menu Tab X again.

Now vb.forms.count shows 3 forms are loaded ( MDI form , Form X & Form Y )!!!!!!!!!!!!!!!

I do not know how Form Y is loaded since this form has not been loaded / activated till now.

Can anyone help me on this ?????

Regain my previous value after close and open

I am using one text box, one label and one command button, i am inserting a numeric no and pressing command the numerical number is displayed in label like wise i enter several nos and it will go on adding in the label. i need a help when i close and open the software the last value in the label should be displayed.


Regain my previous value after close and open

The normal way of doing this is to store the value in a file on your hard disk. Next time your program starts, the value is read back in from the file. Microsoft provides the Windows registry and "ini" files for such purposes, but you can use a simple text file as an easier alternative. VB can't retain values when it isn't running, so you must store any values you need.

Hide null values and remove empty space

Hi, I am new to VB6. I created the vb6 project connecting with a MySQL database. It is working fine. Now I want to print that vb forms. In that MySQL database some fields are empty. In the VB6 forms same text boxes are also empty. How can I hide those text boxes & remove that space and re-size the form in printing.
Name Tel.No
xxxxx 12345
ccccc 56789


need to send text from button1 in form2 to button1 text in form1

Help me,

i need to send text from button1 in form2 to button1 text in form 1.
Form2.Button1.Text = Form1.Button1.Text
I tried this but its not usable. Can any one help me on the code.
Hope you guys will help me.
Have a nice day.

Thanks in advance.

use caption

use caption ;)
form2.button2.caption = form1.button1.caption

Marco Gianelli


I sovled my form unloading problem using this tut...

I've got 2 forms, form1 and

I've got 2 forms, form1 and form2. I want to display form2 on form1 and not in another window, upon clicking the command button.
please help.

please answer my question

i am doing my project in VB6 i used image control and i put picture on that control but when i opened my project on other computer the image is not in that control.. why it is happen?

i am doing my project in VB6

i am doing my project in VB6 i used image control and i put picture on that control but when i opened my project on other computer the picture is not in that control.. why it is happen?

Display selected "record" from SearchForm

I have two Forms. Form1 has a backend Access2007 database. Form2(SearchForm) searches for the quotes in the database. It works wonderfully. Alot of code i retreieved from various sites on the web as my coding for searching didnt seem to be working. Pasted below:
Public Class Search_Form
Dim introws As Integer
'handles the row index number of our table

'determines whether the record is found or not
Dim blnfound As Boolean
'at the start let us assume that a match has no yet been found
'this is called pessimistic programming or something

'Holds the search text from the textbox
Dim strtext As String
'Holds the record value from the chrfname field
Dim strname As String
'Holds the total number of records
Dim inttotrec As Integer
'this is our EOF

Private Sub Search_Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'TODO: This line of code loads data into the 'Stock_In_OutDataSet.REP QUOTE' table. You can move, or remove it, as needed.

End Sub

Private Sub REP_QUOTEBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles REP_QUOTEBindingNavigatorSaveItem.Click

End Sub

Private Sub FindButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindButton.Click

blnfound = False

inttotrec = Stock_In_OutDataSet.Tables("REP QUOTE").Rows.Count
'Moves the record pointer to the first record
'which has a row index number of zero
introws = 0
'Converts the value of the first record of our chrfname field to capital
'letter and assign it to a variable named strname
strname = Stock_In_OutDataSet.Tables("REP QUOTE").Rows(introws).Item("JOB DESCRIPTION")
'Converts the text entered in our search textbox to Uppercase
'The purpose of converting both record values and search text to upper case
'is to compare both values in uppercase form regardless of whatever
'case they were typed initially
strtext = UCase(JobNameTextBox.Text)
'If the searchtext is equal to our record then
If (strtext = strname) Then
'assign true to our blnfound variable
'will be used later whether to display or not
'to display our message box
blnfound = True
'display the record values on their corresponding controls

JobLabel.Text = Stock_In_OutDataSet.Tables("REP QUOTE").Rows(introws).Item("JOB DESCRIPTION")
CustomerNameLabel.Text = Stock_In_OutDataSet.Tables("REP QUOTE").Rows(introws).Item("CUSTOMER")
QuoteNumberLabel.Text = Stock_In_OutDataSet.Tables("REP QUOTE").Rows(introws).Item("QUOTE NUMBER")
End If
'if not equal to the first record then
While (strtext <> strname) And (introws < inttotrec - 1)
'increment the record pointer
introws = introws + 1
'assign the value of the next record pointer to strname
strname = UCase(Stock_In_OutDataSet.Tables("REP QUOTE").Rows(introws).Item("JOB DESCRIPTION"))
'tests if the next record value is equal to the search text
'if yes then
If (strtext = strname) Then
'assign true to our blnfound variable
blnfound = True
'display the record values on their corresponding controls

JobLabel.Text = Stock_In_OutDataSet.Tables("REP QUOTE").Rows(introws).Item("JOB DESCRIPTION")
CustomerNameLabel.Text = Stock_In_OutDataSet.Tables("REP QUOTE").Rows(introws).Item("CUSTOMER")
QuoteNumberLabel.Text = Stock_In_OutDataSet.Tables("REP QUOTE").Rows(introws).Item("QUOTE NUMBER")

End If
'Continue incrementing the record pointer until a match is found
'and the end of file has not been reached
End While
'if the record is not found, display Record not found in our messagebox

If blnfound = False Then
MsgBox("Record not found", MsgBoxStyle.Information, "Search a Record")
End If

End Sub

Private Sub JobNameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles JobNameTextBox.TextChanged

End Sub

Private Sub ViewQuoteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewQuoteButton.Click
Dim currentRow As Integer

currentRow = Stock_In_OutDataSet.Tables("REP QUOTE").Rows(introws).Item("QUOTE NUMBER")

End Sub
End Class

When i press the "View Quote" button, i want to view the quote as if i just pressed the "print" button in Form1. It does that but does not print the selected quote, it generates a new quote. ANY idea what im doing wrong ? (Also a new=bie)

Hello friends

I want to make a web browser in vb but it should work offline because I have not internet connections. Any Suggestions?


Ya.i have one.just use fuck you browser

can you help me out? how to

can you help me out? how to edit a combo box list in form1 from form 2? for example...there is this form where there is a combo list of movies,form1, and there is another form, form2, where you can edit what is the price and the movies in the combo list of form1....

help me

plz send me full toturial about how to display data on form 2 base on the searching from form1.
i have created a database in microsoft access 2007.

(if a standard module is the

(if a standard module is the startup object, it must contain a public subroutine called "Main", and "Sub Main" is specified for the Startup object)

This is not true. In fact, you should rarely ever use Public for Sub Main. It should almost always be Private.

Hi i have created a database

Hi i have created a database in SQL Server and need to import it in to visual basic so that i can create different forms that the user will be able to search for data or display that data that the user has searched. Can anyone please help i need this for a project i am doing for university.



My e-mail is: chrzgt7@hotmail.com.

Send me a message there so I can see what you need for help.


How to pass parameter.

Need help.

I have a form (form1) that contains a field (text1). For "text1", if I key-in a value, it will search into database. But if it doesn't find in the database, it will load another form (form2). In the form2, it will display all the records from the database. After we choose a record in form2, form2 will return a value back to field "text1" in form1.
Form2 is not just being called from form1. It may be called from another forms. So I need to know how form2 return a value back to a field (from another form) that called form2.

Can someone help me?


me too having the same problem

Hope you will help me.

I also having the same problem which i need to send text from button1 in form1 to button.text in form 2. I tried in so many ways and its still not usable. Did u find solution or the code for it. Can you share the code with me. Hope you will help me.

Thanks in advance.

RE: Pass parameter


In this example I've used ListView to display the list of records.
Please see below.

'Place this code after the query returned 0
'If rsRecord.RecordCount = 0 Then
Dim oForm As New Form2
oForm.SourceTextbox = Me.Text1 'source textbox where the selected record id will be returned
oForm.Show 1
Set oForm = Nothing

Form2 Code

Option Explicit

'Here is the source textbox where the selected record id will be returned
Private m_sourceTextbox As TextBox

'This method is use to set the source textbox
Public Property Let SourceTextbox(ByVal source As TextBox)
Set m_sourceTextbox = source
End Property

Private Sub Form_Load()
With Me.ListView1
.ColumnHeaders.Add , , "ID"
.ColumnHeaders.Add , , "Last Name", .Width * 0.4
.ColumnHeaders.Add , , "First Name", .Width * 0.4
.ColumnHeaders.Add , , "Middle Name", .Width * 0.4
.ListItems.Add , , "1"
.ListItems.Add , , "2"
.ListItems.Add , , "3"
End With
End Sub

'If the user's click the record on the ListView it will assign the selected record id on the source textbox
Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
m_sourceTextbox.Text = Item.Text
Unload Me
End Sub

I hope this can help.

Best regards,

From Form2 to Form1

If you load your database in Form2 throught a listview, then the code for returning the value to Form1's text1 is:

Form1.Text1.Text = ListView.ListItem(I)

I don't know how the database is loaded in Form2. But the main idea for the code to send the value from Form2 to Form1 is:

Form1.Text1.Text = (the chosen data)


hey guys,
can anyone help me out with procedures to create a purchase order form using vb6.0??
i am totally new to thiz. do anyone have an idea of it???


please help me how to disable form using vb6.0
when form3 show, form1 and form2 will disable and when you stop the program and when you run it again only form3 will show
can anyone help me??

i need it now
please help thankz

Reload form and edit before saving

i have form1 with Add/Edit command button
when i click add
the textbox control array allows to input on my 10 textbox
the the add button will change to save
when i press save it saves.
the problem is when i edit.
when i press edit i wanted to load again the form with it content
but when i put breakpoints it goes to update immediately.

please help! sorry i'm just starting to learn vb please help.. here is my snippet.

If NameEntry = "ME" Then

For i = 0 To 11

dbname.Seek_DuplicateRecord NameEntry

With dbname.Seek_DuplicateRecord
If .RecordCount <> 0 Then
dbname.Seek_DuplicateRecord NameEntry
Me.txtfield(i).Enabled = True
End If
End With
Next i
''''What to put on this line?? I need the form to show with the content and edit it before it update'''

End If

Saving controls added at runtime

Kinda related question:

I have a form that i have control arrays added to at runtime. I want to have those controls SAVE to the containing form. So that when the program is run again it will have those added controls on it permanently. Is there a way to do this during runtime?

Push the contro array data

Push the contro array data into a File. Read the file into arrays before display. There is no problem of doing this during run time.
If this does not satisfy u, pl elaborate ur problem.

linking login page with main menu page

how could i link a login page ( User name and password) with a main menu page which consist of few optional buttons( such as member registration, member details and back to main menu) to proceed further?

How to pass parameters into forms...

Is it possible to Pass a Parameter to Form2 from Form1?

The project im working on is about loading a thumbnail picture which can be double-clicked to call another form that will show it in bigger size, for a close inspection of pixels or details...

Form1 contains the actual textbox which holds the jpg filename and its file address.... and
Form2 contains the imagebox which has scrolling capability to accomodate the actual big size of the jpg filename stated in Form1

So, upon calling Form2, I need Form1 to pass the jpg filename as a Parameter.
Also, i need to know which form called the form in focus... like in the stack...

Any other idea on how to make a workaround?

Re: How to pass parameters into forms

Hi! Toch,

Yes! It is possible to pass a parameter for Form1 to Form2.

Just follow these steps/procedures.

1.) On your Form2 create a Property Get and Let so that your be able to pass the value of the textbox on the Form1 w/c holds the jpg filename.
On Form 2 (Codes).

Option Explicit

Private m_FilePath As String

Property Let ImagePath(ByVal FilePath As String)

m_FilePath = FilePath

End Property
Property Get ImagePath() As String

ImagePath = m_FilePath

End Property

Private Sub Form_Load()

Call DisplayPicture

End Sub

Private Sub DisplayPicture()

With Me
.Image1.Picture = LoadPicture(ImagePath)
End With

End Sub

2.) After you have created your own Let and Get properties. Here's what you gonna do next.
On Form 1 (Codes)

Option Explicit

Private Sub cmdShowNextForm_Click()

Dim oNextForm As Form2

Set oNextForm = New Form2

With oNextForm
.ImagePath = Me.Text1.Text
.Show 1
End With

Set oNextForm = Nothing
End Sub

There you have it.



re: How to pass parameters into forms...

I found a reference about this but in the form of Access and not VB6, http://www.fmsinc.com/free/NewTips/Access/accesstip13.asp

Also, I learned how to determine which form called the form in focus, by using vbModal on Form.Show
Form1.Show vbModal, Me.Name

The question now is that, when if Form2, how do we extract the parameter passed "Me.Name"?

remove button

hi this site is great! I've learned so many things on this site.. my question is: how do remove an action button(radio button) using command button.

thank you very much!

re sizing a form

How do make my forms to show everything in it ?


my problem is whit object Forms, because Forms is for form loaded, but I need know how load the form or how list all objects forms loaded or unloaded, I need your help

Command select during load/activate

I have the focus set to the command button, but I am not sure how to have the command button selected so that the frame assigned to it is visible. Reasoning for this is due to 1 form with 7 command buttons each with a different frame containing commands specific to the task selected.

creating form at runtime

how do i create a form during runtime using vb 6.0? i created runtime controls and their events using "withevents" but this method is not working with forms. please help me out asap.

Help to generate report in particular format like bills

AM trying to create a system in VB which will store all the data that is enetered by the user for a particular customer, where customer will purchase some items.I want now to generate the bill for the same.Am using Access as backend,can anyone suggest how can i do that?

Code Output

What is the output for the following two codes?

1. Dim intCounter, intNumber As Integer

Private Sub cmdDisplay_Click()
intNumber = 100
For intCounter = 0 To 20 Step 5
intNumber = intNumber – 10
Print intNumber
Next intCounter
End Sub

2. Dim intCount, intNum As Integer

Private Sub cmdDisplay_Click ()
intNum = 9
For intCount = 1 To 10 Step 2
intNum = intNum + intCount
Print intNum;
Next intCount
End Sub


Thank u for ur command for using close form

the out put after running

the out put after running ten times with 2 step is 180

Extra VB activities

Hi. I teach VB and i need a project on using combo boxes and the for loop. It may also contain an If function and option buttons. Do you have any? Thanks a lot.



I have one question, and please answer me on the email: hacker524@hotmail.com...

If I have one form1 = Maximazed, and one button on it that show form2. When I click on that button, form2 will show and you can click form1 but form2 will not hide. Please this is my only qustion, and need answer.

Btw. Great tutorial



Private Sub Command1_Click()
B.Show vbModal
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Is my code correct? B is the name of my 2nd form. It is really not working even when i press exit.
help pls. asap


you should add command button in form2..
here is the code..

Private Sub Command1_Click()
unload me ' to unload form2 and to go back to form1
End Sub

hope this help!good luck

this tutorial is very easy to understand

i am learning visual basic 6 right now, thanks for this easy-to-follow basic tutorial

Re: I got error


I was just passing through and noticed these – characters in the vbcode on this web page!

This is a problem caused by the "MS Frontpage HTML editor". These strange characters are only ment to be just the dash character.

Example: Replace this charcter: – with this dash: -



Ok I dont get anything at all about Vb could some on please help me or teach me step by step

step by step guide on vb

send me ur email address to and i will send simple tutorials to u.


pl send me tutorial on my

pl send me tutorial on my mail

I got error

Hi, I've been working with your tutorial since from its beginning and it is very nice, but I need to ask you why I got error (Sub or Function not defined) when I put CenterForm Me under Private Sub Form_Load() of frmForm 1. Second thing is the alignment of the form on the screen, when I put – error appeared (Compiled error); by the way how to encode those special characters using keyboard? ok thank you very much for spending your time and sharing knowledge with us...more power buddy!

about link

hello..i'm new bie in vb..i want to develop a system..so I have a form that has many button like menu button..so,how can I make that when I click a link button, it shown in the same form not link to other form..example,my menu form name form1 and has button update, delete and add. Form for button update name is form2.when I click button update,form2 is target at form1 means everything is shown at form 1.Same happens to other button..please help me a.s.ap..tq...:)...

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.