Solved

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

Posted on 2010-11-17
9
257 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
[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
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

690 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