I have a little niggling issue that I hope the resident wizards may be able to assist me with.
I’m working on a small desktop app, that is single user and only ever used by myself. It connects to a SQLite DB.
In the main window of the app, there are four controls that require data, 1 listbox and 3 popupmenu’s.
The code to interrogate the data and populate the controls works flawlessly, as does the code to connect to the database.
The sticky part is this :
I split the database related code into 2 areas. First is the connection stuff, second is creating and populating the recordsets into the controls.
When I call the DB.Connect, I set a ‘DBState’ property, located in a module, to the result code of the Connect statement. The DB is not closed at this point, and DBState will usually contain an integer value of zero.
The code that interrogates the DB, creates the recordsets and populates the controls is attached to the open event of the controls themselves.
This approach works for me because I dont need to open and close the database multiple times, I simply connect once, interrogate the database as and when required, then close the database as the program exits.
The code that creates and populates the recordsets will only do so if the DBState has a value of zero.
The crux of this issue is that when the controls are initiated, the DBState is still at -1 (Default), so the DB connection has not yet completed.
What makes it more confusing is that if I remove the code that checks DBState, the controls populate just fine without any errors.
To give this some perspective :
DBOpen method
// define database file, call connect and set DBState to zero if we have connected. Connection remains open.
End
Listbox / PopupMenu open event
// Check DBState for zero value and if so, create recordset and populate control
End
DBState is a property of type integer, default value of -1
What I ultimately want to do is get the db open statements somewhere in the program where they are guaranteed to complete before the open event of the controls attempt to retrieve the data.
I have tried moving the db open code to App.Open, Window.Open and to a ‘DBOpen’ method I created within a module, but the result is the same.
Any thoughts as to what I may be doing wrong here, or how to address this ?
Thanks.