Hi group,

Within one form, I need to run a routine twice. Obviously, I can write the code twice in the two places it needs to run. Isn't there a way to write the routine one time and the call it in two places within the form? Would this be a "Function"?

What I need to write is a fairly large datareader routine. Assuming it is a Function, I'm not sure how to write the event correctly. I can use some help.

In advance, thanks.

Don

Recommended Answers

All 2 Replies

Write it Once and call it from the two places that you wanted to write. I used the following

 Private Sub dgv1_UserAddedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles dgv1.UserAddedRow
        bs.ResetBindings(False)
        **UpdateDatabase()**
    End Sub

    Private Sub dgv1_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles dgv1.UserDeletedRow
        bs.ResetBindings(False)
        **UpdateDatabase()**
    End Sub

   ** Private Sub UpdateDatabase()
        Try
            da.Update(ds, "SAMPLES")
        Catch ex As OleDbException
            MsgBox(ex.ToString)
        End Try
    End Sub**

If you create a Public Module, any routines or variables declared as public, inside the module, can be accessed from anywhere in your project.

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.