Solved

Click button on another form

Posted on 2008-10-25
11
262 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 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

24 Experts available now in Live!

Get 1:1 Help Now