I jst wanna knw...how to pass the value of a text box, of a form as the caption of command button of another form?
Please do lemme knw... :)

Dani AI

Generated

Short summary and next steps based on the thread: showed the simple direct-assignment approach and pointed out calling a public routine on the detail form before showing it. For four project buttons that must all open the same detail form, avoid duplicating code for each button. Give the detail form a clear public entry point (a Sub or Property) that accepts the project identifier or the text to show, and call that from a single click handler.

Example pattern for the detail form (frmProjDetail):

' frmProjDetail
Public Sub DisplayProject(ByVal projectId As String)
    ' populate controls or query DB using projectId
    Me.lblProjectID.Caption = projectId
    Me.Show vbModal
End Sub

Wire the four buttons as a control array on the list form (recommended in classic VB) and store the ID in the Tag for each button:

' frmProjList: cmdProj is a control array (Index 0..3). Each button.Tag = project id string.
Private Sub cmdProj_Click(Index As Integer)
    Dim pid As String
    pid = cmdProj(Index).Tag
    frmProjDetail.DisplayProject pid
End Sub

Notes and troubleshooting:

  • Setting Tag values at design time keeps the click handler generic. Alternatively keep an array of IDs and use Index to look them up.
  • If you need separate instances (no shared state), instantiate the detail form (Dim f As New frmProjDetail) and call the public Sub on that instance, then Unload when done.
  • Validate Tag/projectId before calling the detail form; handle missing IDs gracefully.
  • Avoid tight coupling by not poking at other form controls directly from outside; a public Sub/Property keeps the interface clean (as suggested).
  • If working in VB.NET instead of VB6, use AddHandler or a single event handler with the sender argument to achieve the same single-handler pattern.

Recommended Answers

All 3 Replies

In form2 :

Private Sub Form_Load()
Command1.Caption = Form1.Text1
End Sub

Thanx...bt m havin another problem...
as per my project
"An employee can work under max 4 projects, each having different project id's. Now the problem is...m havin a form which includes the details of the project and there is another form having command btn as Project1, Project2..Project4.Whenever the employee will click on any of the command btn then the form including details of project will b shown."
Now please do lemme knw..that how to use the above coding (by JX-MAN) for all d 4 projects of frmprjlist as i do hav d same form for the detail of all projects (frmprojdetail).
Shall i go for the Array?..if yes then how?
Kindly help me out with this...
Thanx in Advance
Era

¤ Here is an exampe:

10 frmGestionGroupe2.cmdRetour.Caption = "coucou"
20 frmGestionGroupe2.SetLaDate (calDate.value)
30 frmGestionGroupe2.Show 1

¤ Line 10 is probably what you want to do.
¤ Line 20 execute a public function of 'frmGestionGroupe2'.
¤ Line 30 display the form.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.