By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,903 Members | 2,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,903 IT Pros & Developers. It's quick & easy.

Query problems

P: 5
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.
Aug 13 '08 #1
Share this Question
Share on Google+
10 Replies


ADezii
Expert 5K+
P: 8,638
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...
Aug 13 '08 #2

P: 5
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?
Aug 13 '08 #3

ADezii
Expert 5K+
P: 8,638
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?
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
Aug 13 '08 #4

P: 5
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
Aug 13 '08 #5

ADezii
Expert 5K+
P: 8,638
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).
Aug 13 '08 #6

ADezii
Expert 5K+
P: 8,638
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
Aug 13 '08 #7

P: 5
thanks the help is appreciated
Aug 13 '08 #8

ADezii
Expert 5K+
P: 8,638
thanks the help is appreciated
You are quite welcome.
Aug 13 '08 #9

P: 1
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.
Sep 5 '08 #10

ADezii
Expert 5K+
P: 8,638
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
Sep 5 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.