Results 1 to 8 of 8

Thread: listbox-mstable

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2009
    Posts
    21

    listbox-mstable

    no nid
    5 1322
    6
    7
    8
    9
    no nid
    6 66
    8
    1
    i want to add item to msaccess like this.
    here the no field contains listitem.
    i want codings in vb6

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: listbox-mstable

    Try this
    Code:
    'add a reference to the Microsoft ActiveX Data Object Library
    Private Sub Command1_Click
    Dim ADOCn As ADODB.Connection
    Dim ConnString As String
    Dim sSQL As String
    Dim i As Long
    
    ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=c:\yourdatabase.mdb;" & _
            "Persist Security Info=False"
    
    Set ADOCn = New ADODB.Connection
    ADOCn.ConnectionString = ConnString
    ADOCn.Open ConnString
    
    For i = 0 To List1.ListCount - 1
        sSQL = "INSERT INTO yourtablename (fieldname) "
        sSQL = sSQL & "VALUES('" List1.List(i) & "' ")
        ADOCn.Execute sSQL
    Next
    ADOCn.Close
    Set ADOCn = Nothing
    End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2009
    Posts
    21

    Re: listbox-mstable

    thanks for ur reply.
    i try this codings
    error appear in this line
    sSQL = sSQL & "VALUES('" List1.List(i) & "' ")
    ADOCn.Execute sSQL

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: listbox-mstable

    And what would that error be?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2009
    Posts
    21

    Re: listbox-mstable

    syntax error in
    sSQL = sSQL & "VALUES(' " List1.List(i) & " ' ")
    ---------------
    witht hanks
    amala

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: listbox-mstable

    Try this
    Code:
    sSQL = sSQL & "VALUES('" & List1.List(i) & "' "

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2009
    Posts
    21

    Re: listbox-mstable

    i try this code
    error
    ------
    syntax error "insert into statement"
    ADOCn.Execute sSQL //-error
    ----------

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: listbox-mstable

    Do this
    Code:
    For i = 0 To List1.ListCount - 1
        sSQL = "INSERT INTO yourtablename (fieldname) "
        sSQL = sSQL & "VALUES('" & List1.List(i) & "' "
        Debug.Print sSQL '<========= add this line
    '    ADOCn.Execute sSQL
    Next
    After you run it, open the Immediate window and copy 'n paste what is there.

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