Object reference not set to an instance of an object

rockwell

Active member
Joined
Dec 6, 2005
Messages
36
Programming Experience
Beginner
Hi all, i am getting this error when i am trying to display a textbox data from a subform on to a textbox on a main form, i will explain the senario. I have a search button on the main form which brings up a subform where i search a row with an id, for now i am putting the value in a textbox and was trying to display the same value in the mainform in a textbox (my original requirement is different which needs populating many values on the mainform based on a set of ids in the subform). So what i am doing in my subform is

Private mainform As Form1

sub event
mainform.txtmainval.text = txtsubval.text 'subform textbox value
end sub


I an new to vb programming, so was just wondering if someone could help.

Thanks for your time ..
--kris
 
You have to instanciate the form before you can use it:
VB.NET:
Private mainform As Form1

sub event
mainform = New Form1 'This creates the instance of the form
mainform.txtmainval.text = txtsubval.text 'subform textbox value
end sub

OR...

VB.NET:
Private mainform As Form1 = New Form1 'This dims the form AND instanciates it at the same time.

sub event
mainform.txtmainval.text = txtsubval.text 'subform textbox value
end sub

-tg
 
Thanks for your reply tg, i have been trying several options after i posted here and i did this and it didnt give me an error but the value doesnt get reflected in the mainform, it diesnt get displayed in the textbox in the mainform, do we have to do some thing to make it display in the main form ...

Thanks for your time agian ...

--kris
 
Hard to tell w/o knowing just how you are showing the form.

-tg
 
Back
Top