Access - Form list Box data to table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DenamP
    New Member
    • Jun 2011
    • 2

    Access - Form list Box data to table

    Hi everyone,

    I have a form in my database with a list box. The list box values come from a separate table created just to store values for the list box.
    What I want to happen is for the value that a user selects from the list box (in the form) to appear exactly as it is in the main table the form is being used to enter data into.
    This is working, but the text values in the list box are being entered into the main table as numbers. For example, selecting the first text value in the list box would produce a value of '1' in the main table.
    How do I get it to display the actual text value instead?

    Thanks!
  • Mihail
    Contributor
    • Apr 2011
    • 759

    #2
    The value entered in your TextBox is the value for FIRST column in your ListBox (I think here are the IDs for ListBox items and this field is hide in the ListBox.

    Use
    TextBox = ListBox.Columns (n)

    where "n" is the number of column in your table (and in ListBox too). "n" for first column is zero.

    Good luck !

    Comment

    • DenamP
      New Member
      • Jun 2011
      • 2

      #3
      Thanks Mihail. I am afraid I am a bit rusty with Access, where do I enter
      "TextBox"=[ListBox].[Columns]("9")?

      Thanks!
      Last edited by Niheel; Jun 9 '11, 05:30 PM.

      Comment

      • Mihail
        Contributor
        • Apr 2011
        • 759

        #4
        TextBoxName = ListBoxName.Col umns(9)
        Without quotes because the .Columns argument is a number, not a string.

        Comment

        • Mihail
          Contributor
          • Apr 2011
          • 759

          #5
          DenamP !
          Sorry for my misunderstood. There are 2 ways to solve that (at least).

          One is to set the TextBox control source in the Property Sheet pane:

          =[ListBoxName].[Column](9)

          The second is to use the Click event for your list box:

          Code:
          Private Sub ListBoxName_Click()
              TextBoxName = ListBoxName.Column(9)
          End Sub
          I always prefer the VB solution because the flexibility.

          Comment

          Working...