problem with module

bert aalders

Member
Joined
Mar 4, 2011
Messages
16
Programming Experience
Beginner
if i run this program in a form it works fine.
If i put the programming in a module because i want the standard parts in a module it shows nothing.
What am i forgetting?

Module procedures
Public odbcverbinding As Odbc.OdbcConnection
Public Sub klant_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim prdxconnString As String = "Driver={Microsoft Paradox Driver (*.db )};" & _
"DriverID=538;Fil=Paradox 7.X;DefaultDir=E:\nog uit pakken\projecten\VB 2010\toolbox\toolbox_bert\toolbox\database;" & _
"Dbq=E:\nog uit pakken\projecten\VB 2010\toolbox\toolbox_bert\toolbox\database\;CollatingSequence=ASCII;"
odbcverbinding = New Odbc.OdbcConnection(prdxconnString)
odbcverbinding.Open()
Dim str As String
str = "select * from alliancehulp"
Dim odbcadp As New Odbc.OdbcDataAdapter(str, odbcverbinding)
Dim dt As New DataTable("alliancehulp")
Me.DataGridView1.DataSource = dt
odbcadp.SelectCommand.Connection = odbcverbinding
odbcadp.Fill(dt)
odbcverbinding.Close()
End Sub
End
module

Bert
 
That code is trying to handle the Load event of the object. Modules don't have Load events. That's a member of the Form class, so it only works in forms.

If you want code like that in a module then it would make sense to write a function that returned a DataTable. In the Load event of each form, you call the method and get a populated DataTable back, which you can then bind to a grid or whatever.
 
Back
Top