Results 1 to 6 of 6

Thread: save listbox contents to a table

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    362

    save listbox contents to a table

    please can somone instruct me how to make my access app save the contents of a listbox into a table.

    thanks

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: save listbox contents to a table

    If this is in Access VBA, then create a new ADODB Command object. Create your SQL INSERT statement by reading all the items in the listbox, you may end up with several INSERT statements. Then for each insert statements, execute it using the command object against your database.

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

    Re: save listbox contents to a table

    Code:
    Dim i As Long
    Dim sSQL As Long
    For i = 0 to List1.ListCount - 1
       sSQL = "INSERT INTO yourtable (fieldname) VALUES ('" & List1.List(i) & "') "
       yourcommandobject.Execute sSQL
    Next

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    362

    Re: save listbox contents to a table

    Hack when you say

    yourcommandobject.Execute sSQL

    what does the "yourcommandobject" mean, what should i put here? and will this (hacks example) work the same for a textbox with multiple lines of text?

    i appreciate your assistance.

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

    Re: save listbox contents to a table

    The reason for the loop is to handle multiple lines. Multiple lines, in fact, are assumed.

    How to you connect to your database?

    If you are using ADO, then you have a connection object.

    It is what you declared as: As ADODB.Connection

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    362

    Re: save listbox contents to a table

    cheers thanks hack ill give it a shot

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