Click here to Skip to main content
15,912,294 members
Home / Discussions / Database
   

Database

 
AnswerRe: Write to text file from a sql server stored-procedure [modified] Pin
flippydeflippydebop30-Oct-06 22:40
flippydeflippydebop30-Oct-06 22:40 
Questioninserting values from select query Pin
dj.rock30-Oct-06 19:46
dj.rock30-Oct-06 19:46 
AnswerRe: inserting values from select query Pin
neilsolent31-Oct-06 0:54
neilsolent31-Oct-06 0:54 
QuestionHow to store an 1:N tree (Hierarchy) Pin
peterchen30-Oct-06 14:52
peterchen30-Oct-06 14:52 
AnswerRe: How to store an 1:N tree (Hierarchy) Pin
Colin Angus Mackay31-Oct-06 4:37
Colin Angus Mackay31-Oct-06 4:37 
AnswerRe: How to store an 1:N tree (Hierarchy) Pin
Damodar Periwal31-Oct-06 9:46
Damodar Periwal31-Oct-06 9:46 
AnswerRe: How to store an 1:N tree (Hierarchy) Pin
Eric Dahlvang1-Nov-06 11:31
Eric Dahlvang1-Nov-06 11:31 
QuestionMicrosoft Access VBA Question About ListBoxes... Pin
new_phoenix30-Oct-06 14:15
new_phoenix30-Oct-06 14:15 
I have a project that involves a MS Access database. I need to take a listbox that is populated with a SELECT DISTINCT list of records from a database. I need to take the results from the listbox selections and assign it to the IN CLAUSE from a SQL statement as in:

SELECT FIELD1, FIELD2, FIELD3 FROM TABLE1 WHERE FIELD1 IN ('101001', '101002', '010003', '101004', '101005') ORDER BY FIELD2

If the list box control's name is lstExcludeViaControls then I suspect that the code to parse the selected items from the control should be:

' Declare variables and assign values
Dim count as Integer
Dom count_compare as Integer
count = 0
count_compare = 0

' Count the number of selected items from the list box
For Each listItem in lstExcludeViaControls.SelectedItems
    count = count + 1
Next

' Concatenate the value to a variable and add a comma if the 
number of items selected from the list box is less than the 
total number of items selected, and if the number of items 
is equal to the total number of items selected from the list box, 
then do not add a comma.

For Each listItem in lstExcludeViaControls.SelectedItems
   If count_compare < count Then
      listItem = listItem + "'" + lstExcludeViaControls.Selected + "', "
   else
      listItem = listItem + "'" + lstExcludeViaControls.Selected + "'"
   End If
   count_compare = count_compare + 1
Next


Please provide some additional insights regarding how to approach this issue. How do I create a variable that is based upon the assembly a string of fields selected from the list box box? This variable would then need to be passed to the CRITERIA portion of a query. The string variable in the IN CLAUSE requires parameters to be provided to the SQL statement as:

WHERE FIELD1 NOT IN ('101001', '101002', '101003', '101004', '101005')

Confused | :confused: Confused | :confused: Confused | :confused:
QuestionSQL Select Puzzle Pin
neilsolent30-Oct-06 9:51
neilsolent30-Oct-06 9:51 
AnswerRe: SQL Select Puzzle Pin
Eric Dahlvang31-Oct-06 3:07
Eric Dahlvang31-Oct-06 3:07 
QuestionWhere can I lean about stored procedures? Pin
CCMint30-Oct-06 7:01
CCMint30-Oct-06 7:01 
QuestionCOPY TABLE giving unexpected EOF error Pin
Zeolite30-Oct-06 6:55
Zeolite30-Oct-06 6:55 
QuestionBest way to save data Pin
knappster30-Oct-06 1:43
knappster30-Oct-06 1:43 
QuestionADO.NET related question Pin
Imtiaz Murtaza30-Oct-06 0:57
Imtiaz Murtaza30-Oct-06 0:57 
AnswerRe: ADO.NET related question Pin
Colin Angus Mackay30-Oct-06 1:54
Colin Angus Mackay30-Oct-06 1:54 
GeneralRe: ADO.NET related question Pin
Damodar Periwal31-Oct-06 10:14
Damodar Periwal31-Oct-06 10:14 
AnswerRe: ADO.NET related question Pin
Hunuman30-Oct-06 2:02
Hunuman30-Oct-06 2:02 
GeneralData Type Issue in Where Clause Pin
Brady Kelly30-Oct-06 0:13
Brady Kelly30-Oct-06 0:13 
JokeRe: Data Type Issue in Where Clause Pin
Rob Graham30-Oct-06 3:14
Rob Graham30-Oct-06 3:14 
Questionselect query filling 2 typed datasets Pin
steve_rm29-Oct-06 22:10
steve_rm29-Oct-06 22:10 
QuestionPurpose of SQL Server Jobs Pin
King Shez29-Oct-06 19:50
King Shez29-Oct-06 19:50 
AnswerRe: Purpose of SQL Server Jobs Pin
Eric Dahlvang30-Oct-06 3:13
Eric Dahlvang30-Oct-06 3:13 
Questionconnection cannot be made? Pin
Haoman1729-Oct-06 0:48
Haoman1729-Oct-06 0:48 
Questionconnecting to SQL express through ADO Pin
psasidisrcum28-Oct-06 11:54
psasidisrcum28-Oct-06 11:54 
AnswerRe: connecting to SQL express through ADO Pin
Jerry Hammond28-Oct-06 16:16
Jerry Hammond28-Oct-06 16:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.