Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    fill combobox1 (6.0)

    Why error in this code? i would want to select all records from table USER_name in field NOMINATIVO and insert/show in combobox???????

    Option Explicit
    Private Sub Form_Load()

    Dim oConn As ADODB.Connection
    Dim oRS As ADODB.Recordset
    Dim sSQL As String


    Set oConn = New ADODB.Connection
    With oConn
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .Open "c:user.mdb"
    End With


    sSQL = "SELECT NOMINATIVO, FROM USER_NAME"
    Set oRS = New ADODB.Recordset
    oRS.Open sSQL, oConn, adOpenForwardOnly, adLockReadOnly, adCmdText

    With oRS
    If Not (.BOF And .EOF) Then
    Do Until .EOF
    cboAutoComplete.AddItem .Fields("ComboboxText").Value
    cboAutoComplete.ItemData(cboAutoComplete.NewIndex) = .Fields("ID").Value
    .MoveNext
    Loop
    Else
    MsgBox "No records found"
    End If
    End With


    CloseRecordset oRS
    CloseConnection oConn
    End Sub
    Public Sub CloseConnection(oConn As ADODB.Connection)
    If Not oConn Is Nothing Then
    If (oConn.State And adStateOpen) = adStateOpen Then
    oConn.Close
    End If
    Set oConn = Nothing
    End If
    End Sub
    Public Sub CloseRecordset(oRS As ADODB.Recordset)
    If Not oRS Is Nothing Then
    If (oRS.State And adStateOpen) = adStateOpen Then
    oRS.Close
    End If
    Set oRS = Nothing
    End If
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: fill combobox1 (6.0)

    What error are you getting or what result is unexpected? It is rather unreasonable to expect others to read and interpret your code to track down any possible error without knowing what they're looking for. You'll get faster replies if you are more specific about the problem.
    Charlotte

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: fill combobox1 (6.0)

    If you get the error on oRS.Open, check the following:

    <code>sSQL = "SELECT NOMINATIVO, FROM USER_NAME"</code>


    I believe it is illegal to have a comma at the end of the SELECT clause, you only use it between field names in the SELECT clause. Try this instead:

    <code>sSQL = "SELECT NOMINATIVO FROM USER_NAME"</code>

Posting Permissions

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