Solved

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

Posted on 2010-11-17
9
249 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
Comment Utility
Why not just put
frmvoucher.TextBox1.Text = "blahblah"
in the On_Click event of the checkbox?
0
 

Author Comment

by:running32
Comment Utility
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
Comment Utility
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
 

Author Comment

by:running32
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 37

Expert Comment

by:TommySzalapski
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

9 Experts available now in Live!

Get 1:1 Help Now