Listbox selection altering table value

G

Guest

I have a form with one listbox on it. This form is populated from a table
that contains one field. The user can pick one or more company IDs from
that table, hit continue, and then data is pulled from another table based on
that company ID, and transferred to an Excel spreadsheet.

My problem is after running this, for some reason the first record in the
table is replaced with a blank. And so the listbox shows up with a blank at
the top, since it's pulling from the table.

I even tried to work around this by having the table with company IDs
repopulated each time from the master table. That's fine, unless the user
runs this once and then decides to run it again without starting over and
repopulating the table, because once run, the first record is replaced by an
empty string or null or something.

My code is as follows -- this is the only code that touches the listbox.
Everything else seems to work. thanks in advance

For intCounter = 0 To (lstOrgNames.ItemsSelected.Count - 1)
intSelectedIndex = lstOrgNames.ItemsSelected.Item(intCounter)
strCompanyName = lstOrgNames.ItemData(intSelectedIndex)
strCompanyTableName = "temp_tbl" & strCompanyName
strSQL = "SELECT Orgname,Account, Total, Classification INTO " &
strCompanyTableName & _
" FROM " & gstrSourceTableName & " WHERE orgname =
'" & strCompanyName & "'"
cnn.Execute strSQL
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9,
strCompanyTableName, CurrentProject.Path & "\" & strCompanyTableName, True
Next intCounter
 
J

John Smith

Sounds to me as though you have a bound control where you need an unbound one.
If you are using a listbox (or combo) to select a search criteria then the
control needs to be unbound or it will be updating whatever table it is bound to.

HTH
John
##################################
Don't Print - Save trees
 

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