Solved

Click button on another form

Posted on 2008-10-25
11
261 Views
Last Modified: 2012-05-05
I have added a button on another form to perform an action. I want to open that form and click the button. Here is the code to open the form but the last line gives me an error. "Reference to a non shared member requires an object reference"

The button on the other form is public.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        frmIncidentReport.TblPersonsBindingSource.AddNew()
        Dim frm As New frmPersons(frmIncidentReport.TblPersonsBindingSource)
        Dim result As DialogResult = frm.ShowDialog
        frm.Dispose()
        If result = Windows.Forms.DialogResult.OK Then
        End If
        frmPersons.Button2_Click(Nothing, Nothing)     '<<<<< Problem>>>>>
    End Sub
0
Comment
Question by:wiswalld
  • 6
  • 4
11 Comments
 
LVL 1

Expert Comment

by:_Choggo_
Comment Utility
you need to reference the object instead of the class name, that would basically solve your problem,
but you really should look into another solution for your problem overall

the code you posted is trying:

creates a new form
shows it blocking the execution and saving that result for later use
you then remove the object from memory
then you have an empty if statement
and now you're trying to click a button on a non existing object, since you disposed of it before hand...

        frm.Button2_Click(Nothing, Nothing) 

Open in new window

0
 
LVL 13

Author Comment

by:wiswalld
Comment Utility
I had the if state ment commented out so I just removed it for this post. So the problem is I dispose of the second form before calling the button click?
0
 
LVL 13

Author Comment

by:wiswalld
Comment Utility
So how to word this?
0
 
LVL 13

Author Comment

by:wiswalld
Comment Utility
Is this because the binding source on frmpersons is set from another form to that binding source?
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
Comment Utility
frmPersons.Button2.PerformClick()

Wayne
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 13

Author Comment

by:wiswalld
Comment Utility
Same error. I tried this with a function with same result. I removed the dispose but no luck. Basically what I want to do is copy all the fields from a datagridview to the frmpersons form after I open creating a new record based on an existing record.
0
 
LVL 13

Author Comment

by:wiswalld
Comment Utility
Don't think this matters but this is the button click

 Public Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.CaseNumberTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(1).Value
        Me.DivisionPrecinctComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(2).Value
        Me.PersonTypeComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(3).Value
        Me.LastNameTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(4).Value
        Me.FirstNameTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(5).Value
        Me.MiddleTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(6).Value
        Me.JrTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(7).Value
        Me.StreetTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(8).Value
        Me.BuildingNumberTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(9).Value
        Me.AptNumberTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(10).Value
        Me.CityComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(11).Value
        Me.StateComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(12).Value
        Me.ZipCodeTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(13).Value
        Me.HomeNumberTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(14).Value
        Me.HomeExtTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(15).Value
        Me.WorkNumberTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(16).Value
        Me.WorkExtTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(17).Value
        Me.SSNTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(18).Value
        Me.DOBComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(19).Value
        Me.AgeFromTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(20).Value
        Me.AgeToTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(21).Value
        Me.AgeTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(22).Value
        Me.SexComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(23).Value
        Me.RaceComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(24).Value
        Me.EthnicityComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(25).Value
        Me.AKALastTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(26).Value
        Me.AKAFirstTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(27).Value
        Me.AKAMiddleTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(28).Value
        Me.AKADOBComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(29).Value
        Me.AKASSNTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(30).Value
        Me.CautionComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(31).Value
        Me.ConditionComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(32).Value
        Me.SkinComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(33).Value
        Me.HeightTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(34).Value
        Me.WeightTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(35).Value
        Me.HairComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(36).Value
        Me.EyesComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(37).Value
        Me.GlassesComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(38).Value
        Me.BuildComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(39).Value
        Me.ReligionComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(40).Value
        Me.MaritalStatusComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(41).Value
        Me.EmployedComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(42).Value
        Me.BeardComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(43).Value
        Me.MoustacheComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(44).Value
        Me.OccupationTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(45).Value
        Me.POBTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(46).Value
        Me.USCitizenComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(47).Value
        Me.EducationTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(48).Value
        Me.ResidenceStatusComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(49).Value
        Me.EmployerNameTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(50).Value
        Me.EmployerStreetTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(51).Value
        Me.EmployerBuildingNoTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(52).Value
        Me.EmployerAptNoTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(53).Value
        Me.EmployerCityTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(54).Value
        Me.EmployerStateTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(55).Value
        Me.EmployerZipCodeTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(56).Value
        Me.PictureTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(57).Value
        Me.PictureDateComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(58).Value
        Me.PictureTimeTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(59).Value
        Me.ScarsComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(60).Value
        Me.MarksComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(61).Value
        Me.TattoosComboBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(62).Value
        Me.DescriptionTextBox.Text = frmAddPersonsSearchMatch.TblPersonsDataGridView.CurrentRow.Cells(63).Value
    End Sub
0
 
LVL 1

Accepted Solution

by:
_Choggo_ earned 125 total points
Comment Utility
if you dispose it, it means you won't be using it anymore, so you should dispose it after you are actually done with the object, after the button click

if you want o access the button's method by class name you should use Shared as well, no just public

if you do frm.Button2_Click since you made the method public, it should work...

0
 
LVL 1

Expert Comment

by:_Choggo_
Comment Utility
You could also use webtubbs's suggestion, make the button public then through the form's object access frm and not frmPersons
0
 
LVL 13

Author Comment

by:wiswalld
Comment Utility
I see what the problem. I was calling frmpersons.button2_Click not frm.button2_Click

You got it Choggo. I did not see that.

Thanks
0
 
LVL 1

Expert Comment

by:_Choggo_
Comment Utility
glad to be of assistance
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now