hi....actually wen i am loading a form from the module.....its loaded but its not holding on to the screen and it is performing the actions listed in the form load procedure......can anyone tell me what should i do to make the form hold on to the screen....it would be of great help....thanx...

Hi,

Are u sure Form's Visible = True...?
Instead of calling a Form In Module, Do it the other way-round.
Change the Start-Up Form To the First Form,
and in that Form-Load, Call the Module Procedure.

Regards
Veena

First try to understand why a form is loaded (made visible). It is either to attract the user with some message or for some input/selection. You are not supposed to write any code other than that in the form load event. Only a control in the form if activated by the user or if it elapse in time in its visibility, then only other procedures should start.
In assence a form actually is a tool to invite the participation of the user for a specific action/s he or she wants to do. Keep that in mind while writing the code inside the form_load. Check up the code inside the form_load(). You will find the actual bug.

And also you should SetFocus to some of the controls in the so called form_load.

Take out the codes for db connection and recordset from the called form_load and paste it in the module before the form_load line. When the form_load is invoked from that module control is passed to that form_load(). The recordset is still avilable to you in the just loaded form. open it. Read the required data from the database. Fill the data on the different contols in the form and set focus to any control in the form. There you are.

thank you so much sir.....it almost worked out...but it is showing an error "object required " alongside when the form is opened.....when i try to debug it...it takes the control in the form where i am accessing the record set....

Natuarally I thought it will happen. First try to declare the variable cnn and recordset as a global varaible so that from any sub you can access them.
Otherwise. you can do one thing. In the module where you invoked the form_load() just pass the recordset to the form_load.
Example
formx_load myRecordeSet

and in the form_load module

Private Sub Formx_Load(myRecordSet)

if both variable are same it is OK

Now I will tell you one simple debugging technique.

Put as many MsgBox in the program where you find you are struck up.
for example in you module where you are trying to accee the form_load
place this line.

MsgBox "I have set up the connection and passed the recordset to the formload "
then place the code

formx_load myRecordSet

Then in the
Private Sub Formx_load(myRecordSet)

MsgBox "I am inside the formx_load and I got the recordset and now I am going to open it"

then Open the record set and select the fields from the Database.
again give

MsgBox "Now I have read the data"

Likewise you can debug beautifully

i have tried the above given procedure also....but the problem still remains the same ...that is the form which i am calling from the module isnt holding on the screen......the control immediately passes on to the next step in the module....

I am very sorry to keep you so long. I have been out.
The only alternative thing can be some thing wrong with your
formx.show
To get hold of the consecutive forms you had to mention with the sow the model

Formx.Show vbModel

Revert the code to the earlier state and change the show in this way.
I think it has to work.
Get back to me immediately if it works or tomorrow I will try to help you.

i am thankful to you sir for taking such interest.....i have tried
Formx.Show vbModel also but its not working out

i just worked outhe problem by using your way of inserting message boxes.....and wow it worked out to be absolutely fine.....thanks a lot for giving this brilliant idea...

Now, we will approach your problem in some other way. First see, you are having a main program which starts from form_load() which is associated with the first form you have created. In this load event you might have suuplied some values to the different controls on the form. Is it not? Well, then you might have expected some user clicking some control. eg. command1_Click().

Ok in this module you might have some coding and after that or a seperate subroutine where you want the second form you have created to be loaded.

Remember every form whether it is the first one or the next or the next... all are an instance of the object form. Here you are changing the name or vb will put form2, form3 etc.
then in the form2 you again have form_load() as the first module in it. Also it has its own text1,command1 etc controls which you have designed and this you have to distinguish with the first one.

In the main module you just call this form by its name form2 or formx with a show atribute.

Form2.Show vbModel
Remember that a form though looks like a subroutine, it has some restriction.

for example, from your main program instead of you giving

form2.Show vbModel

if you give

form2_load()

it is wrong. Because show and load are not mutually exclusive.
the show command looks after which form is to be activated. And remember every form is associated with its own form_load(). It is not good programing practice to change Form_Load() to Form(some name)_Load() and from some other module invoke it.

After making the required changes please reply to this thread. I am online.

Sub Main()
Load Form1
Form1.visible = True
Form1.Show
End Sub

That's true. But you cannot invoke like a subroutine form1_load.
Load form1 and form_Load are two distinctive actions. The later one is associated with the form you have created by the VB Wizard.

i was able to do it sir by the way u told me....i.e coding as formx.show......and thanx a lot for your helpful guidance

And please, what AirtsuaLiera has communicated is not very good programming code. When you set a form visible the show won't work (it is actually duplicating the code, and again for multiple forms the Model parameter makes it just hold on to the screen.
Load form1
form1.visible=true
form1.show may or may not work for the first form but it will deffenitely Not work for multile forms.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.