[Last Call] Learn how to a build a cloud-first strategyRegister Now


MDI form Error

Posted on 2004-11-11
Medium Priority
Last Modified: 2010-04-24
I'm getting the following error occasionally when I load my initial MDI form:

"Object reference not set to an instance of an object".

It happens on the following line of code:

            frmMain.ActiveForm.Text = "Centre : " & BranchName & " (" & UserCentre & "); User: " UserFullName & " (" & LCase(Username) & ")"

It doesn't happen all the time the application is loaded which makes it very hard to figure out why the eroror is occuring. Does anyone have any ideas?
Question by:PeterErhard

Expert Comment

ID: 12562295
break the line down into
frmMain.ActiveForm.Text = "Centre : "
frmMain.ActiveForm.Text = frmMain.ActiveForm.Text + BranchName
frmMain.ActiveForm.Text = frmMain.ActiveForm.Text + " (" + UserCentre
.... etc

to find out which variable isnt getting initialised properly.
LVL 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 12567116
The ActiveForm property may be returning Nothing if the application is still loading and no form is yet active:

    "A Form that represents the currently active form, or a null reference (Nothing in Visual Basic) if there is no active form."

Where are you executing this line of code from?

    Dim f As Form = frmMain.ActiveForm
    If Not (f Is Nothing) Then
        f.Text = "Centre : " & BranchName & " (" & UserCentre & "); User: " UserFullName & " (" & LCase(Username) & ")"
        MsgBox "No Active Form"
    End If

Instead of changing the form text is this manner, why not place code in that forms load event?


Author Comment

ID: 12581194
Thanks for that - appears to have worked!

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question