Solved

Click button on another form

Posted on 2008-10-25
11
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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