Clearing all fields in another form

Hi,

I've made 2 forms; Application and Results, where Results displays the information entered in Application. Application has a public sub (btnClear_Click) that clears all fields in the form, which I allso want to run from Results, clearing the fields in Application.

(The point is by clicking OK in Results it clears all the fields in Application and then Results closes itself)

Please help if u can, I need to solve this for an assignment due today(!!)

Cheers!
QiddeesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DotNetLover_BaanCommented:
Hi there..
in your Results form, inside the click event handler of OK button, use...

Dim ApplForm As New Application
ApplForm.btnClear_Click(Nothing, Nothing)

-Baan
0
QiddeesAuthor Commented:
Hi, thanks for your quick reply!

I did as suggested but Application does not clear its fields (Results form closes as it's supposed to do after Application has cleared).

Clicking on the clear button in the Application form still works. This is the code for it:

-----------------
Public Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtSurname.Text = ""
        txtDate.Text = ""
        txtForenames.Text = ""
        txtContactNo.Text = ""
        txtPostalCode.Text = ""
        cbNationality.SelectedIndex = -1
        txtPassportNo.Text = ""
        txtAddress1.Text = ""
        txtAddress2.Text = ""
        txtEducation.Text = ""
        rbDivorced.Checked = False
        rbFemale.Checked = False
        rbMale.Checked = False
        rbMarried.Checked = False
        rbSingle.Checked = False
        cbCourse.SelectedIndex = -1
End Sub
--------------

Could this has something to do with it?
0
QiddeesAuthor Commented:
Third line in last post should be:

I did as suggested but Application does not clear its fields (Results form closes as it's supposed to do after trying to clear Application fields).
                                                                                                                                                         ^^^^^^^^^^^^^^^^^^^^^
0
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Or you can handle it all from the Application form by delcaring a variable of type Results as WithEvents, allowing you to trap when the Results form has been closed and call btnClear_Click() as shown below.

Public Class Application
    Inherits System.Windows.Forms.Form

    Private WithEvents r As Results

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        r = New Results
        r.Show()
    End Sub

    Private Sub r_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles r.Closed
        btnClear_Click(Nothing, Nothing)
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

    End Sub

End Class

0
QiddeesAuthor Commented:
Sounds even better!
How do I declare a variable as WithEvents?
0
DotNetLover_BaanCommented:
Hi again,
why don't you use MODULE ?  Instantiate all the forms there. Then you can access any form from any other form.
Add a Module to your project. and write this inside... Module...End Module.

Module MyModule1
    Public F1 As New Form1
    Public F2 As New Form2

    Sub main()
        F1.showdialog()
    End Sub
End Module

Then to access F1's subs from F2, just use..
F1.Btn_Clear(Nothing,Nothing)

-Baan
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
It's all in my previous post.  =)

If you want the Results form to be Modal (meaning you can't continue with or select any other form in your application until the Results form is closed) then it would be much simpler to open it using ShowDialog() like this:

Public Class Application
    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim r As Results = New Results
        ' Pass info to your results form...
        r.ShowDialog() ' Code will not continue until Results is closed...
        btnClear_Click(Nothing, Nothing) ' Clear the current Application form...
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

    End Sub

End Class
0
Daniellus83Commented:

Your are thinking to difficult.

> you make 2 forms. One main (FormApplication) and one other (FormResults).


Try to explain it as simple as possible:


> Put this code in the form FormResults:
----------------------------------------------------------------------------------------
    Public myCaller As FormApplication
----------------------------------------------------------------------------------------



> Then put this into your main form (Application) in the on_load_event :

----------------------------------------------------------------------------------------
        Public FormFormClone As Form_Result = New FormResult
        FormResultsClone.myCaller = Me
----------------------------------------------------------------------------------------

> Make the from FormResultsClone visible (or hide it) using this code (put this under a button_click_event in FormApplication:
----------------------------------------------------------------------------------------
   FormResults.show
   FormResultsClone.hide
----------------------------------------------------------------------------------------


Now you will be able to access from your Application the form Results, but also the way round!


So you can e.g. clear all textboxes in FormResults from FormApplication by this code:
----------------------------------------------------------------------------------------
FormResultsClone.textbox1.text = ""
...
..
.
FormResultsClone.textbox9.text = ""
----------------------------------------------------------------------------------------


Try it and maybe you like it!

Daniël
0
Daniellus83Commented:

Sorry made a mistake, the code

   Public FormFormClone As Form_Result = New FormResult

Must be outside(!) the on_load_event of FormApplication...


--------------- furthermore:

The code behind the OK button on the FormResult should be:

   FormApplication.btnClear_Click


And add this code to the Sub  btnClear_Click:

  FormResultsClone.hide
-------------------------------------------------------------------------

0
Daniellus83Commented:
too bad..

in my last post:

  FormApplication.btnClear_Click

must be:

  mycaller.btnClear_Click
0
Daniellus83Commented:

okay.. I made you an example:

     http://www.danieltrommel.com/download/expl02.zip

unzip this solution and you'll know.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
QiddeesAuthor Commented:
Hi! Thanks for all your effort!!

I had to hand in the assignment without solving the problem yesterday, but I've tried it now and it works perfectly!

Cheers! :)

-Qiddees-
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.