Connecting Tech Pros Worldwide Forums | Help | Site Map

Query problems

Newbie
 
Join Date: Aug 2008
Posts: 5
#1: Aug 13 '08
I have a query which works perfectly but I wish to iterate through the query and select specific portions from the query such as ID, address which can then be sent to perform another function.

My current solution is to fill a listbox with the required information however I have no idea how to extract the values, I have tried a solution with combobox however, upon iterating through all the items to select them the items remain unselected and thus Comobox.text has a null value.

Any help would be appreciated.

ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,216
#2: Aug 13 '08

re: Query problems


We will need much more detail that that which you have provided, such as:
  1. Table the Query is based on.
  2. Field Names and their Data Types that comprise the Query.
  3. Specific Fields you wish to extract.
  4. Where do you wish to extract these Field values to? List Box, Combo Box, etc.
  5. What is the Name of the Object that will accept these values?
  6. etc...
Newbie
 
Join Date: Aug 2008
Posts: 5
#3: Aug 13 '08

re: Query problems


1. Table the Query is based on.
2. Field Names and their Data Types that comprise the Query.
3. Specific Fields you wish to extract.
4. Where do you wish to extract these Field values to? List Box, Combo Box, etc.
5. What is the Name of the Object that will accept these values?
6. etc...


The table the query is based on is a generic table (tbl1) all field names are based on client listing, the ones that the comprise the query are CandidateName, phone, email. all of which are text data type.
I wish to extract the phone data from the query into a listbox/combobox then into a memo box

Since the listbox/combobox already contains the data items i wish to extract I would like to know how to extract the information from the listbox and put into the memo box, or would it be simpler to use a recordset and iterate through the set returned by the query?
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,216
#4: Aug 13 '08

re: Query problems


Quote:

Originally Posted by Jaxter1

1. Table the Query is based on.
2. Field Names and their Data Types that comprise the Query.
3. Specific Fields you wish to extract.
4. Where do you wish to extract these Field values to? List Box, Combo Box, etc.
5. What is the Name of the Object that will accept these values?
6. etc...


The table the query is based on is a generic table (tbl1) all field names are based on client listing, the ones that the comprise the query are CandidateName, phone, email. all of which are text data type.
I wish to extract the phone data from the query into a listbox/combobox then into a memo box

Since the listbox/combobox already contains the data items i wish to extract I would like to know how to extract the information from the listbox and put into the memo box, or would it be simpler to use a recordset and iterate through the set returned by the query?

Quote:
Since the listbox already contains the data items i wish to extract I would like to know how to extract the information from the listbox and put into the memo box
  1. What exactly do you mean by Memo Box?
  2. In what format do the wish the Phone Numbers in the List/Combo Box extracted? e.g.
    Expand|Select|Wrap|Line Numbers
    1. (215) 888-1234;(234) 876-8936;(679)-0018
    Expand|Select|Wrap|Line Numbers
    1. (215) 888-1234
    2. (234) 876-8936
    3. (679)-0018
    Expand|Select|Wrap|Line Numbers
    1. (215) 888-1234, (234) 876-8936, (679)-0018
Newbie
 
Join Date: Aug 2008
Posts: 5
#5: Aug 13 '08

re: Query problems


Quote:
1. What exactly do you mean by Memo Box?
2. In what format do the wish the Phone Numbers in the List/Combo Box extracted? e.g.
Code: ( text )
1.
(215) 888-1234;(234) 876-8936;(679)-0018

Code: ( text )
1.
(215) 888-1234
2.
(234) 876-8936
3.
(679)-0018

Code: ( text )
1.
(215) 888-1234, (234) 876-8936, (679)-0018

I would prefer the phone numbers to be extracted as your third example shows,
by memo box i mean a textual area sorry for confusion
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,216
#6: Aug 13 '08

re: Query problems


Quote:

Originally Posted by Jaxter1

I would prefer the phone numbers to be extracted as your third example shows,
by memo box i mean a textual area sorry for confusion

Stand by, I should have an answer for you within a couple of hours. Oops, here comes the boss, gotta go! (LOL).
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,216
#7: Aug 13 '08

re: Query problems


Quote:

Originally Posted by ADezii

Stand by, I should have an answer for you within a couple of hours. Oops, here comes the boss, gotta go! (LOL).

OK, boss has gone. Assuming your List Box is named lstPhone and your Text Box is named txtPhoneNos, the following code will do the trick:
Expand|Select|Wrap|Line Numbers
  1. Dim strBuild As String
  2. Dim intCounter As Integer
  3. Dim intNumOfEntries As Integer
  4.  
  5. intNumOfEntries = Me![lstPhone].ListCount
  6.  
  7. If intNumOfEntries > 0 Then
  8.   For intCounter = 0 To intNumOfEntries - 1
  9.     strBuild = strBuild & Me![lstPhone].ItemData(intCounter) & ", "
  10.   Next
  11.   Me![txtPhoneNos] = Left$(strBuild, Len(strBuild) - 2) 'remove trailing ", "
  12. Else
  13.   Me![txtPhoneNos] = vbNullString
  14. End If
Newbie
 
Join Date: Aug 2008
Posts: 5
#8: Aug 13 '08

re: Query problems


thanks the help is appreciated
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,216
#9: Aug 13 '08

re: Query problems


Quote:

Originally Posted by Jaxter1

thanks the help is appreciated

You are quite welcome.
Newbie
 
Join Date: Sep 2008
Posts: 1
#10: Sep 5 '08

re: Query problems


Quote:

Originally Posted by ADezii

OK, boss has gone. Assuming your List Box is named lstPhone and your Text Box is named txtPhoneNos, the following code will do the trick:

Expand|Select|Wrap|Line Numbers
  1. Dim strBuild As String
  2. Dim intCounter As Integer
  3. Dim intNumOfEntries As Integer
  4.  
  5. intNumOfEntries = Me![lstPhone].ListCount
  6.  
  7. If intNumOfEntries > 0 Then
  8.   For intCounter = 0 To intNumOfEntries - 1
  9.     strBuild = strBuild & Me![lstPhone].ItemData(intCounter) & ", "
  10.   Next
  11.   Me![txtPhoneNos] = Left$(strBuild, Len(strBuild) - 2) 'remove trailing ", "
  12. Else
  13.   Me![txtPhoneNos] = vbNullString
  14. End If

Hi, this code is cool. Now, what I'm tryin is to iterate thru the second column of the combo box as my combo box has two columns. What it will do is iterate through the second column and compare values in those columns with the one passed and if matched it will return the value in the same row but from the first column. Can you please help me how I can achieve this. Thank you.
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,216
#11: Sep 5 '08

re: Query problems


Quote:

Originally Posted by jaeezzy

Hi, this code is cool. Now, what I'm tryin is to iterate thru the second column of the combo box as my combo box has two columns. What it will do is iterate through the second column and compare values in those columns with the one passed and if matched it will return the value in the same row but from the first column. Can you please help me how I can achieve this. Thank you.

I'm a little fuzzy on your request, but here is generic code that will iterate through all Values in the 2nd Column of a Combo Box named cboNames, and compare them to an Unknown Value:
Expand|Select|Wrap|Line Numbers
  1. Dim intCounter As Integer
  2. Dim intNumOfEntries As Integer
  3.  
  4. intNumOfEntries = Me![cboNames].ListCount
  5.  
  6. If intNumOfEntries > 0 Then
  7.   For intCounter = 0 To intNumOfEntries - 1
  8.     If Me![cboNames].Column(1, intCounter) = "<some value>" Then
  9.        'take some action here
  10.     End If
  11.   Next
  12. End If
Reply


Similar Microsoft Access / VBA bytes