Solved

Click button on another form

Posted on 2008-10-25
11
265 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_
ID: 22802862
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
ID: 22802872
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
ID: 22802883
So how to word this?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 13

Author Comment

by:wiswalld
ID: 22802888
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)
ID: 22802907
frmPersons.Button2.PerformClick()

Wayne
0
 
LVL 13

Author Comment

by:wiswalld
ID: 22802936
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
ID: 22802941
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
ID: 22802945
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_
ID: 22802952
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
ID: 22802974
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_
ID: 22802986
glad to be of assistance
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show/Hide ASP.NET controls with JQuery best practices 3 90
Adding Existing Item to vb.net Project causes Errors 4 43
SqlServer no dupes 25 37
VB.NET 2008 - SQL Timeout 9 34
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

839 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