I have a form set up where I want to run the function PopulateGrid
on it's Form_Load event. I have initialized the DB connection as follows:
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadConfigFile()
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & config("DatabasePath") & ";")
cn.Open()
End Sub
Now, I want to run the PopulateGrid
function directly after I connect to the database as shown above. I'm confused as to how I'd use a database query in a module when the database is initialized in my main form. Would simple setting the variable cn
to public work? Or do I have to do something more complex?
Thanks.