Query problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jaxter1
    New Member
    • Aug 2008
    • 5

    Query problems

    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
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    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...

    Comment

    • Jaxter1
      New Member
      • Aug 2008
      • 5

      #3
      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?

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        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?
        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.
          Code:
          (215) 888-1234;(234) 876-8936;(679)-0018
          Code:
          (215) 888-1234
          (234) 876-8936
          (679)-0018
          Code:
          (215) 888-1234, (234) 876-8936, (679)-0018

        Comment

        • Jaxter1
          New Member
          • Aug 2008
          • 5

          #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

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            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).

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              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:
              Code:
              Dim strBuild As String
              Dim intCounter As Integer
              Dim intNumOfEntries As Integer
              
              intNumOfEntries = Me![lstPhone].ListCount
              
              If intNumOfEntries > 0 Then
                For intCounter = 0 To intNumOfEntries - 1
                  strBuild = strBuild & Me![lstPhone].ItemData(intCounter) & ", "
                Next
                Me![txtPhoneNos] = Left$(strBuild, Len(strBuild) - 2) 'remove trailing ", "
              Else
                Me![txtPhoneNos] = vbNullString
              End If

              Comment

              • Jaxter1
                New Member
                • Aug 2008
                • 5

                #8
                thanks the help is appreciated

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  Originally posted by Jaxter1
                  thanks the help is appreciated
                  You are quite welcome.

                  Comment

                  • jaeezzy
                    New Member
                    • Sep 2008
                    • 1

                    #10
                    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:
                    Code:
                    Dim strBuild As String
                    Dim intCounter As Integer
                    Dim intNumOfEntries As Integer
                    
                    intNumOfEntries = Me![lstPhone].ListCount
                    
                    If intNumOfEntries > 0 Then
                      For intCounter = 0 To intNumOfEntries - 1
                        strBuild = strBuild & Me![lstPhone].ItemData(intCounter) & ", "
                      Next
                      Me![txtPhoneNos] = Left$(strBuild, Len(strBuild) - 2) 'remove trailing ", "
                    Else
                      Me![txtPhoneNos] = vbNullString
                    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.

                    Comment

                    • ADezii
                      Recognized Expert Expert
                      • Apr 2006
                      • 8834

                      #11
                      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:
                      Code:
                      Dim intCounter As Integer
                      Dim intNumOfEntries As Integer
                       
                      intNumOfEntries = Me![cboNames].ListCount
                       
                      If intNumOfEntries > 0 Then
                        For intCounter = 0 To intNumOfEntries - 1
                          If Me![cboNames].Column(1, intCounter) = "<some value>" Then
                             'take some action here
                          End If
                        Next
                      End If

                      Comment

                      Working...