First you have to make that method Public. Then you need an instance of that form to actually call its method.
Visual Basic:
Dim SomeForm As New FormType 'create a new instance of the form
SomeForm.DoSomething() 'call its method
If you already have an instance of a form and dont want to create a new one you can do it by creating a class with shared members that will hold the instances. Or by passing the instance between the forms using constructors. If you need examples on those two just say
here is what i am working on which is causing me problems
i have 3 forms, a main for with 2 buttons to go to the other forms
for 2
for entering data into a text file
here i open a file to write to and enter data and so forth..
form 3
for reading the file entries that i put in with form 2
the problem is when i have one form open i get an error because the file is already open and can't access the file to read when the second form is open still..
i have tried to close the form when i click the read button but it still gives me the error...so i am stumped as of right now
also on my enter info form (form 2) i have a mask edit button for a phone number....when i enter data and then submit it
then exit the enter form (close) and then try to enter the form 2 again from the main form i get an error as well
' object reference is not set to an instance of an object'
You could do this the following way:
Create two variable that will hold instances of your two additional forms: (somewhere at the top of your form)
Visual Basic:
Dim formOne As FormType
Dim formTwo As FormTwoType
'just subsititute this with the names you are using : )
Then, each time you want to show the form you would do something like this:
Visual Basic:
formOne = New FormType
'now the variable will contain a new instance of the form
'and you will be able to access the form using that variable
This will prevent the error that you are getting. Using the Close() method also disposes of the from if its not shown as a dialog so the instance is no longer available. So next time you want to show it, it will create a new one. If you only want to have one instance of the form without creating new ones, you could always hide it instead of closing it.
To send a form to back you would use its SendToBack method.
If you just want to make inactive you would set focus another one using Focus() method the form.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.