Results 1 to 5 of 5

Thread: combo box nightmares

  1. #1

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    42

    combo box nightmares

    hi
    I have a combo box that pulls the data from a look up table present in the SQL server.
    I am getting this weird error
    "string or binary data would be truncated"

    This only happens when the drop down list has strings like
    "voice_and_data"
    "handset_in_closet"

    Can some one please help
    The code is

    Private Sub load_cmbMbl()
    Dim conSQL As ADODB.Connection

    'Sets connection
    Set conSQL = New ADODB.Connection

    Dim strSQLServer As String
    Dim strSQLDatabaseToOpen As String
    Dim strConnectString As String
    Dim strSQL2 As String


    strSQLServer = "sfdaqsql1"
    strSQLDatabaseToOpen = "techlog_copy"
    strConnectString = "Provider=sqloledb;" & _
    "Integrated Security=SSPI;" & _
    "Data Source=" & strSQLServer & ";" & _
    "Initial Catalog=" & strSQLDatabaseToOpen & ";"

    conSQL.Open (strConnectString)

    cmbMbl.Clear

    Dim rsRecords As ADODB.Recordset
    Set rsRecords = New ADODB.Recordset

    strSQL2 = "SELECT mobile_test FROM Mobile_Test_Lookup"
    rsRecords.Open strSQL2, conSQL
    If Not (rsRecords.BOF And rsRecords.EOF) Then
    rsRecords.MoveFirst
    Do
    cmbMbl.AddItem rsRecords.Fields
    rsRecords.MoveNext
    Loop Until rsRecords.EOF
    End If
    rsRecords.Close

    Set rsRecords = Nothing
    conSQL.Close
    End Sub

    Please help

  2. #2
    Junior Member
    Join Date
    May 2005
    Location
    Litchfield, IL
    Posts
    22

    Re: combo box nightmares

    You ommitted the field name to use to add to the combobox :

    Do
    cmbMbl.AddItem rsRecords.Fields
    rsRecords.MoveNext

    should be:

    Do
    cmbMbl.AddItem rsRecords.Fields("fieldname")
    rsRecords.MoveNext

    Hope that helps
    - ILJester

  3. #3

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    42

    Re: combo box nightmares

    I am still getting the same errror.

    Dim rsRecords As ADODB.Recordset
    Set rsRecords = New ADODB.Recordset

    strSQL2 = "SELECT status FROM Status_Lookup"
    rsRecords.Open strSQL2, conSQL
    If Not (rsRecords.BOF And rsRecords.EOF) Then
    rsRecords.MoveFirst
    Do
    cmbStatus.AddItem rsRecords.Fields("Status").Value
    rsRecords.MoveNext
    Loop Until rsRecords.EOF
    End If
    rsRecords.Close

  4. #4
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: combo box nightmares

    hi
    I have a combo box that pulls the data from a look up table present in the SQL server.
    I am getting this weird error
    "string or binary data would be truncated"

    is this the line that the error is generated?
    VB Code:
    1. cmbStatus.AddItem rsRecords.Fields("Status").Value

    if so, what is the value of rsRecords.Fields("Status").Value?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: combo box nightmares

    I would just use the field number

    VB Code:
    1. .Fields(0)

    Which would be the first field returned from your database

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width