Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    anavagomez is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Apr 2017
    Posts
    31
    I was able to fix that part and also to load the sql server data-table values into an array, here is the code in case you want to see if I am making a mistake:

    Code:
    Private Sub LoadArray()
        
        On Error GoTo errhandler
        
        Dim ADOCon As ADODB.Connection
        Dim ADORS As ADODB.Recordset
        Dim avarRecords As Variant
        Dim intRecord As Integer
        
        Set ADOCon = New ADODB.Connection
        ADOCon.ConnectionString = GetConnectionString("Conn")
        ADOCon.Open
        
        Set ADORS = New ADODB.Recordset
        ADORS.ActiveConnection = ADOCon
        ADORS.Open _
                    "SELECT DISTINCT" & _
                    "  [Category]" & _
                    ", [ProductDescription]" & _
                    ", [BasePrice]" & _
                    ", [AdditionalPrintPrice]" & _
                    ", [MinimumPurchaseAmount]" & _
                    ", [isChoral]" & _
                    ", [isScoringBasedMinAmount]" & _
                    ", [isTierBased]" & _
                    "FROM [dbo].[Price] " & _
                    "ORDER BY Category", , adOpenStatic, adLockReadOnly
                    
        avarRecords = ADORS.GetRows(50)
        
        Debug.Print UBound(avarRecords, 2) + 1 & " records retrieved."
        
        For intRecord = 0 To UBound(avarRecords, 2)                
            
    		PriceCategory.AddItem (avarRecords(0, intRecord) & ";" & _
                                   avarRecords(1, intRecord) & ";" & _
                                   avarRecords(2, intRecord) & ";" & _
                                   avarRecords(3, intRecord) & ";" & _
                                   avarRecords(4, intRecord) & ";" & _
                                   avarRecords(5, intRecord) & ";" & _
                                   avarRecords(6, intRecord) & ";" & _
                                   avarRecords(7, intRecord))
                
        Next intRecord   
    
    
    eofit:
        
        On Error Resume Next
        ADOCon.Close
        ADORS.Close
        Set ADOCon = Nothing
        Set ADORS = Nothing
    
    
        Exit Sub
    
    
    errhandler:
        
        z = ErrorFunction(Err, Err.Description, Erl, "LoadArray", , True)
        
        Err = 0
        
        Select Case z
            Case 0: Resume Next
            Case 1: GoTo eofit
        End Select
        
    End Sub

    One issue I am still experiencing is that there is one record that has a "ProductDescription" value of:


    Easy Play (Piano, Guitar) or Banjo

    When I look at this value in the combo-box, the value is splitted in 2 columns:

    Col1 Col2
    Easy Play (Piano Guitar) or Banjo

    I think this is due to the comma in between the string containing the description. Do you know how to escape this character so the string gets written all together?


    Thank you.

  2. #17
    anavagomez is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Apr 2017
    Posts
    31
    I was able to fix the "comma" issue. Within the For loop:

    Code:
    For intRecord = 0 To UBound(avarRecords, 2)
            
            If InStr(avarRecords(1, intRecord), ",") > 0 Then
                avarRecords(1, intRecord) = """" & avarRecords(1, intRecord) & """"
            End If       
                
            PriceCategory.AddItem (avarRecords(0, intRecord) & ";" & _
                                   avarRecords(1, intRecord) & ";" & _
                                   avarRecords(2, intRecord) & ";" & _
                                   avarRecords(3, intRecord) & ";" & _
                                   avarRecords(4, intRecord) & ";" & _
                                   avarRecords(5, intRecord) & ";" & _
                                   avarRecords(6, intRecord) & ";" & _
                                   avarRecords(7, intRecord))
                
        Next intRecord

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 03-01-2016, 06:05 AM
  2. Replies: 1
    Last Post: 05-21-2014, 12:38 AM
  3. Replies: 7
    Last Post: 02-25-2014, 03:11 PM
  4. Replies: 2
    Last Post: 12-02-2012, 09:14 PM
  5. Replies: 0
    Last Post: 01-09-2009, 03:10 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums