Solved

write to textbox on another form when action happens on 1st form

Posted on 2010-11-17
9
251 Views
Last Modified: 2012-05-10
I need to write to a textbox on frmvoucher when a checkbox is selected on frmgeneric.  

I can do this inside the activation code but my problem is when the form has already been opened the activation will not be triggers.

Thanks
'>>>>> frmvoucher

Private Sub frmPAIssueVouchera_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated

        checkreason()
    End Sub
    Public Sub checkreason()
        If chkreason <> "" Then
            Dim generic
            Dim letterrequested
            Dim letteronfile
            Dim copay
            Dim other
            'check to see if textbox2 has any of the reasons in it."
            generic = "Brand name not requested, generic vouchered."
            letterrequested = "Brand name requested, by physician, letter requested."
            letteronfile = "Brand name requested, by physician, letter on file. "
            copay = "Brand name requested, by client, co-pay adjusted."
            other = "Other: Add a note in Staff Notes."
            If InStr(TextBox2.Text, generic) Then
                TextBox2.Text = Replace(TextBox2.Text, generic, " ")
            End If
            If InStr(TextBox2.Text, letterrequested) Then
                TextBox2.Text = Replace(TextBox2.Text, letterrequested, "")
            End If
            If InStr(TextBox2.Text, letteronfile) Then
                TextBox2.Text = Replace(TextBox2.Text, letteronfile, "")
            End If
            If InStr(TextBox2.Text, copay) Then
                TextBox2.Text = Replace(TextBox2.Text, copay, "")
            End If
            If InStr(TextBox2.Text, other) Then
                TextBox2.Text = Replace(TextBox2.Text, other, "")
            End If
            If InStr(TextBox2.Text, F2.UserName, CompareMethod.Text) Then
            Else
                TextBox2.Text = TextBox2.Text + "    " + F2.UserName
            End If
        End If
        formopen = False
    End Sub

'>>>>> frmgenerics

    Public ReadOnly Property UserName() As String
        Get
            Return chkreason
        End Get
    End Property

Open in new window

0
Comment
Question by:running32
9 Comments
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34158132
Why not just put
frmvoucher.TextBox1.Text = "blahblah"
in the On_Click event of the checkbox?
0
 

Author Comment

by:running32
ID: 34158169
this is the error I get when I try to put that statement into frmgeneric.

Reference to a non-shared member requires an object reference.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34158194
Is your textbox public? If it's private, the other form won't be able to touch it. Did you set up your forms so they could see each other like putting both in the same class?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 

Author Comment

by:running32
ID: 34158298
I was just using a form inside my windows VS project.   I'd really like to learn how to change these forms so both forms can see each others control.  Could you tell me.

thanks
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34158366
Did you start the project as a Windows application or a Windows Forms application?
I don't have VS here so I can't test stuff, but I assume you only use one instance of each form, so you can just declare both of them in the same main form or main application.
0
 

Author Comment

by:running32
ID: 34158421
The project was started as a Windows application within Visual Studio.   I then right clicked on the application and added a new form.  Form there VS created the template for the form and when you drag a textbox onto the form it takes care of the inital declaration.  

  'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.

    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 34158434
You can keep a reference to the one form in another form. So if FormA opens FormB and FormB needs to write to FormA's textbox then

1) Declare a public variable in FormB which is of type FormA

Public frmA As FormA

2) When launching FormB from FormA, set the frmA variable

Dim f as new FormB
f.frmA = me
f.show

3) Then you can use this variable

frmA.Textbox1.Text = "Some Text"

You could store this reference variable anywhere such as in a module or main form.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34158435
I'll have to test it later today when I'm back at home with my computer. Maybe someone else will chime in before then.
0
 
LVL 5

Expert Comment

by:srinivasbn
ID: 34159239
If you are declaring the both forms in an mdi form and access those two forms it will be more easy.

Take an mdi form (frmMDI)
declare the two forms in the frmMDI as follows.

public fVoucher as frmVoucher = new frmVoucher
public fGenerics as frmGenerics = new frmGenerics

now in your frmGenerics checkbox checked event you can write the following code to access the text box and enter the text for frmVoucher text box.

dim frMDI  as frmMDI = ctype(me.MdiParent, frmMDI)
frMDI.fVoueher.TextBox1.Text = "Chaged text"




Srinivas.
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

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 …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

860 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