"object instance not set to an instance of an object vb.net" happens when switch form

ssfftt

Well-known member
Joined
Oct 27, 2005
Messages
163
Programming Experience
1-3
"object instance not set to an instance of an object vb.net" happens when switch form

i have these 2 lines of code causing problem "object instance not set to an instance of an object vb.net" :
VB.NET:
                dim frm2 as new frm2
                frm2.DsGetAllQs.Clear()
                frm2.SqlDataAdapterGetAllQs.Fill(frm2.DsGetAllQs)

i have frmStart, frm1, and frm2.
In frmStart, i have a btnStart contains code: frm1.show, me.hide
In frm1, i have the code above to be executed when itself is shown. when first time the btnStart is clicked, the code in frm1 execute fine. also on frm1 i have btnGoToFrm2 which contains code frm2.show, me.hide
In frm2, i have a btnReturn contains code: frm1.show, me.hide. when i click on btnReturn, frm2 is hide and frm1 is shown.
Now if i click on btnGoToFrm2 on frm1 again, a message shows: "object instance not set to an instance of an object vb.net". beside this message, everything will still work as expected.
I located the error source, which is the code on the top. Can anyone help plz?
btw, the DsGetAllQs and SqlDataAdapterGetAllQs are visually dropped on to frm2 in design view
 
i checked everything, from my limited knowledge, i cant figure it out, plz help
However, nothing is actually affected by the error message, so... if you cant figure it out either, maybe you can suggest a way to hide the messge?
 
NEVER, EVER do this: dim frm2 as new frm2

Ever.....

The variable name really should be something else. Call it Form2 for all I care... but never, ever use the same name for the variable name for the form or class name.

The reason: frm2.DsGetAllQs.Clear()
Is that referring to a static object .... or the object in the instance of the form? I don't know and neither does the compiler.

-tg
 
thx TechGnome, i tried the way you suggested, did this: dim frm21 as new frm2
the error message still exists, can u help more plz?
 
well, actually i have the frm declared in datamodule, everytime i want it, just call it. in the datamodule, now i have dim frm21 as new frm2, and when i use it in other forms, i just call datamodule.frm21.show, and datamodule.frm21........ (whatever i need to do)
Should do dim frm21 as new frm2 all the time under every single procedure that requires frm2 instead?
 
to be honest, i dont think the dim frm21 (or frm2) as new frm2 in this case is a big issue, becasue i use it everywhere else in my project, it works just fine, however, only in this case, the dataset in frm2 is called in frm1, it gives error (doesnt affect anything at all).

btw, in other parts of my project, as long as the frms do not contain datasets that might be called from another form, the error message never show up. which means, only the problem of the dataset. either caused by the problem u identified or the dataset itself.

confusing :(
 
ok, see attached frm2 code (full) and frm1 code (partial), the frm2 is actually called frmTesting1, frm1 is frmTestList
on datamodule(moduleUser), i have:
Public frmTestList1 As New frmTestList
Public frmTesting1 As New frmTesting

actually i dont think u will feel good reading my code, too messy, sorry, I cant get rid of the error myself. hopefully u can identify the problem
thx alot
 

Attachments

  • frm1 code partial _problematic area.txt
    7.3 KB · Views: 29
  • frm2 code.txt
    43.1 KB · Views: 27
Back
Top