Problems when modifying a listbox

J

John

I've got a listbox on a form that is being populated after the form is
opened, based on user input to other fields. If they enter different
information, I want to repopulate that listbox based on the new
information, but things start acting a little strange after I do
that. Part of the process involves using a wscript.shell object to
run a command. It's supposed to wait until the command is finished
before continuing, but it behaves differently after I modify a listbox
than before.

I'm able to replicate the problem with the following code, assigned
to button click on a form with the listbox, called list1. The
rowsourcetype is set to "value list".

Set objShell = CreateObject("Wscript.Shell")
List1.RowSource = ""
runreturn = objShell.Run("Notepad.exe", 1, True)
MsgBox (runreturn)


The message box will pop up before notepad is closed, and the return
value comes back as 259. If I comment out the list1.rowsource = ""
line, the message box waits until notepad is closed before popping up
and the return value from the objshell.run is 0.

Couple of things I've noticed:
If I insert a message box before the objshell.run, everything works
fine.
If I repeat the objshell.run command three times, it starts working
the expected way again.
The same thing happens if I try to change the rowsourcetype or if I
try to use list1.removeitem, however clearing any selected items works
fine.
Whatever changes I make to listbox are successfully made, the
objshell.run just starts acting differently afterwards.

I'm using Access 2003 SP3, and tried it using a file in both 2000
format and 2002/2003 format. I also run into the same issue in Access
2002.
 

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