I’m just coding a simple database app that uses a tabpanel on the main window. I have the usual settings that I normally use which are:
App.module (dbModule)
dbModule property ‘UsersDB’ as ‘SQLiteDatabase’ ’ The one and only global declaration used
Window1 open event:
Dim UsersDB as New SQLiteDatabase
UsersDB.DatabaseFile = GetFolderItem("DatabaseFileName") ' Real database file name inserted here
If UsersDB.Connect Then
Msgbox("Database opened OK")
Else
Msgbox("Database failed to open")
End
All works as expected so far and the database opens correctly. I then have a tabpanel front & centre on Window1. When the user selects a tab, the ‘Change’ event for the tabpanel looks like this:
Select Case Me.Value
Case 0
Msgbox("Tab 0")
Case 1
Msgbox("Tab 1")
Case 2
Msgbox("Tab 2")
Case 3
Msgbox("Tab 3")
Case 4
Msgbox("Tab 4")
UpdateTabPanel4
End
‘UpdateTabPanel4’ (Which is a method of Window1) then contains this code :
Dim rs As RecordSet
rs=UsersDB.SQLSelect(SQL Statement goes here)
I then get a nil object exception for ‘rs’ at line 2 for the SQLSelect, suggesting that the database connection is not visible or accessible at this point.
Shouldn’t this talk to the database connection I’ve already established ? Or do I need to repeat the code from the Window1 open event in each of the methods used when a tabpanel is selected ? I thought that since the tabpanel is a child of Window1 that the connection I have already established would be visible.
Have I missed something obvious ?