Greetings Everyone,

We have many forms in an Attendance application I am writing for a local school. The first form is called formBrowseAttendance and the other form is called formBrowseStudents.

In formBrowseAttendance is a textbox called editBoxStudentID.

Inside the double click event of a grid in the formBrowseStudents I am trying to populate the value of the textbox in formBrowseAttendance with this code:

Private Sub LightGridStudents_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LightGridStudents.MouseDoubleClick
        ' Load the values double clicked into the attendance details section.
        '--------------------------------------------------------------------
        FormBrowseAttendance.editBoxStudentID.Text = LightGridStudents.CurrentRow.Cells(0).Value

        MessageBox.Show(LightGridStudents.CurrentRow.Cells(0).Value)

        Me.Close()
    End Sub

The messagebox shows the ID but it's not showing up in the formBrowseAttendance textbox even though there are not compile errors.

Please see attachment.

Can you tell me what I'm missing?

Thanks.

Truly,
Emad

Greetings Everyone.

I thought of including some form information about our project.

We would like to populate several textboxes in formBrowseAttendance while form formBrowseStudents currently has focus.

We made the following changes:

In form formBrowseAttendance :

Public Sub RefreshDetails(ByVal pStudentID As Integer)
        strSqlStatement = _
            "SELECT LTrim(Student.FirstName) & ' ' & LTrim(Student.LastName) AS StudentName, " & _
                   "Int((Date()-dob)/365.25) AS Age, " & _
                   "Parent.HomePhone, " & _
                   "Parent.Email " & _
             "FROM Student INNER JOIN Parent ON Student.ParentId = Parent.ParentId " & _
            "WHERE StudentID = " & pStudentID

        ' Declare a connection object.
        '-----------------------------
        Dim objConnection As OleDbConnection = Nothing

        ' Create the connection object to use an SQL query and open it.
        '--------------------------------------------------------------
        objConnection = New OleDbConnection(My.Settings.ISGL_Database)

        ' Set up a command to execute a query.
        '-------------------------------------
        objCommand = New OleDbCommand(strSqlStatement, objConnection)
        objCommand.CommandType = CommandType.Text

        Try
            ' Get the Student details from the database using a DataReader.
            '--------------------------------------------------------------
            objConnection.Open()
            strResultFromQuery = objCommand.ExecuteScalar()

            MessageBox.Show(strResultFromQuery)

            objDataReader = objCommand.ExecuteReader

            While objDataReader.Read
                editBoxStudentName.Text = objDataReader("StudentName")
                EditBoxAge.Text = objDataReader("Age")
                EditBoxHomePhone.Text = objDataReader("HomePhone")
                EditBoxEmail.Text = objDataReader("Email")
            End While

            objConnection.Close()

            EditBoxClassID.Focus()

        Catch ex As Exception
            MessageBox.Show(ex.Message)

        Finally
            objConnection.Close()
        End Try

In the formBrowseStudents:

Private Sub LightGridStudents_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LightGridStudents.MouseDoubleClick
        FormBrowseAttendance.RefreshDetails(LightGridStudents.CurrentRow.Cells(0).Value)

        MessageBox.Show(FormBrowseAttendance.editBoxStudentName.Text)

        Me.Close()
    End Sub

If you look at the code in form formBrowseAttendance, you will see a messagebox. The messagebox shows that the datareader does indeed return data.

If you look at the code from form formBrowseStudents, the messagebox also shows that the textbox does have data.

When form formBrowseStudents is closed, there is no data showing in the form formBrowseAttendance texboxes.

Maybe it has something to do with focus?

Thanks.

Truly,
Emad

Greetings Everyone,

I created a small app that shows the same problem.

Form1 shows form2 and form2 shows form3. From form2 I can change the value of the textbox on that form but from form3 I can't change the textbox value in form2.

Please can you look at the application and correct it so I can change the value in the textbox of form2 from form3.

Thanks.

Truly,
Emad

Get a reference of Form2 object from the OpenForm collection.

Public Class Form3

    Private Sub ButtonSaySomethingInForm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSaySomethingInForm2.Click
        Dim fm As List(Of Form2) = Application.OpenForms.OfType(Of Form2)().ToList()

        If IsNothing(fm) = False Then
            MsgBox(fm(0).TextBoxValue.Text)
            fm(0).TextBoxValue.Text = TextBoxValue.Text
        End If

    End Sub
End Class
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.