Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Listbox from Access Database

Listbox from Access Database

Scheduled Pinned Locked Moved Visual Basic
databasedesignhelptutorial
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I'm working on a program that is the front end for a database (Access). One of the fields in the data base is set up to use options set in the field's 'Row Source' during design of the database. (When viewing the records in Access it comes up as a list box) I am wondering how I can get the options for that field into my program without hardcoding them. I can get the option that is currently chosen for a record back, but I need to know how to get ALL the possible options for that field. I'm using ADODB objects to access the database. Any help or pointers in the right direction will be much appreciated. Quinn

    N 1 Reply Last reply
    0
    • L Lost User

      I'm working on a program that is the front end for a database (Access). One of the fields in the data base is set up to use options set in the field's 'Row Source' during design of the database. (When viewing the records in Access it comes up as a list box) I am wondering how I can get the options for that field into my program without hardcoding them. I can get the option that is currently chosen for a record back, but I need to know how to get ALL the possible options for that field. I'm using ADODB objects to access the database. Any help or pointers in the right direction will be much appreciated. Quinn

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      If you are using the ADO object in your application, do a simple query:

      Select [YourField] from [YourTable]

      Once you have executed that SQL statement say when the form loads, you can add items with something like:

      ListBox.Clear()
      Do While Not adors.EOF
      ListBox.Add(adors("[YourField]"))
      Loop

      HTH Nick Parker

      L 1 Reply Last reply
      0
      • N Nick Parker

        If you are using the ADO object in your application, do a simple query:

        Select [YourField] from [YourTable]

        Once you have executed that SQL statement say when the form loads, you can add items with something like:

        ListBox.Clear()
        Do While Not adors.EOF
        ListBox.Add(adors("[YourField]"))
        Loop

        HTH Nick Parker

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        That didn't work. Stoopid IE made me lose my reply and I'm too tired to type it again. In short, that will only return the one option that a row has as a value. If one of the options were never selected it wouldn't show up in the list box. :) Thx though. Anything else you can suggest? Quinn

        N J 2 Replies Last reply
        0
        • L Lost User

          That didn't work. Stoopid IE made me lose my reply and I'm too tired to type it again. In short, that will only return the one option that a row has as a value. If one of the options were never selected it wouldn't show up in the list box. :) Thx though. Anything else you can suggest? Quinn

          N Offline
          N Offline
          Nick Parker
          wrote on last edited by
          #4

          Are you saying such as if someone were to hold down the shift key when clicking the mouse inside the listbox, thus selecting multiple items? Is your question on how to get the value of all those selected items? :confused: Nick Parker

          1 Reply Last reply
          0
          • L Lost User

            That didn't work. Stoopid IE made me lose my reply and I'm too tired to type it again. In short, that will only return the one option that a row has as a value. If one of the options were never selected it wouldn't show up in the list box. :) Thx though. Anything else you can suggest? Quinn

            J Offline
            J Offline
            James T Johnson
            wrote on last edited by
            #5

            I think if you alter Nick's query so it starts out as SELECT DISTINCT .... it should give you the values you need. James Simplicity Rules!

            L 1 Reply Last reply
            0
            • J James T Johnson

              I think if you alter Nick's query so it starts out as SELECT DISTINCT .... it should give you the values you need. James Simplicity Rules!

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Sorry James, but the SELECT DISTINCT change didn't help either. :( Nick: What I am needing is, in Access, when viewing a table it can be set up so that when you are entering data into the database directly that a list box will open for a particualr field and display the options that you can select for that field. Such as a 'Gender' Field. A list box will show the options 'No Answer', 'Male', 'Female' so you can choose one of those three options for the record. If in all the records for that table only 'No Answer' and 'Male' have been chosen, I need a way for my program to also recieve 'Female' to add to MY list box, so that it can be selected in my program. I hope that helps clarify what I am looking to do using ADODB. The actualy field I need to do this with isn't Gender, but it makes for an easy example, else I'd be hardcoding all the live long day. Thx again for the tries. :) Quinn

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups