Problem with a form, a listbox, an sql query and a subroutine

K

Keith

Hello,

I’m having an interesting problem with a form and hope I can adequately
explain it.

Here goes.

I have 5 objects

1. Form1
2. Listbox1 (in Form1)
3. Some sql code that is in Listbox1
4. Table1
5. MySub1

Form1 is the main form that does some tasks I need to accomplish
Form1 contains Listbox1.

Listbox1 gets data from Table1 using an SQL query that links to Table1

Every time Form1 loads, the Form Load subroutine runs and that sub runs
MySub1 which is located in a module, and is supposed to update Table1. the
update is accomplished by deleting all the data in Table 1 and then
repopulating the table with new data.

My intention is to have MySub1 run before the Listbox1 SQL runs so that the
most current data are available when Listbox1 runs.

Unfortunately, it appears that the Listbox1 connection gets made before
MySub1 runs, and MuSub1 gets locked out and is unable to delete records and
repopulate Table1.

I know that MySub1 works, because it does its job if run on its own, and it
does its job if it is connected to a command button in another form that is
not Form1.

So here’s a question that seems to be relevant.
Is there any sub that runs BEFORE Form1’s Load subroutine, where I could
place my call to MySub1?

If not, is there another work-around that might achieve the goal?

Thanks very much,

Keith
 
G

George Nicholson

One approach:

In design view, leave ListBox1.Recordsource blank.

In the FormLoad event:

Call MySub1
DoEvents
ListBox1.Recordsource = "Some sql code"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top