Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

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

Posted on 2010-11-17
9
Medium Priority
?
263 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
Technology Partners: 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!

 

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 2000 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

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!

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…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

647 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