Results 1 to 12 of 12
  1. #1
    New Lounger
    Join Date
    May 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Auto Select (Access 97)

    I have a list box on a form that is based on a combo box. When a selection is made in the combo box, the list box returns the correct number, but I have to click the number in the list box to select it so it will write to the table. (the list box only returns 1 possible record for each combo box selection) Is ther a way to make the list box automatically select the record, or...is it possible to use a text box, and put the query as the default value so there is no need to make a selection?
    Thanks.

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Auto Select (Access 97)

    I don't understand why you have a combo box and a listbox, as it seems from your description that a selection in the combo box is supposed to select a single record from the listbox? Could you explain it a little more, maybe with an example?
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

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

    Re: Auto Select (Access 97)

    Are you looking for the default value property of the listbox?
    Charlotte

  4. #4
    New Lounger
    Join Date
    May 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto Select (Access 97)

    To clarify, the combo box is for tool ID #. When the tool ID # is selected, the standard pieces per hour the tool should produce pops up in the list box. I need both numbers to write to the table. Would a two column box be more appropriate? Maybe I just didn't think of that because I've never done one. :-) I know I've seen two column list boxes, but is a two column combo box possible?
    Thanks

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

    Re: Auto Select (Access 97)

    Comboboxes can have multiple columns if you base the combobox on a query that returns multiple fields. You have to set the number of columns in the properties dialog of the combobox and you also have to set the bound column, which is the one that actually gets saved to the table.
    Charlotte

  6. #6
    New Lounger
    Join Date
    May 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto Select (Access 97)

    The problem is, I need both numbers to write to the table. If only one column can write to the table, then I'm back at square one. Here's the thing, the standard pieces per hour change from time to time, and I need the current standard recorded at the time of the entry so that the reports can calculate efficiencies properly. This is how I ended up with two boxes to begin with.
    It actually works well with the combo box, and the list box, but for the number that pops up in the list box to write to the table, I have to click it, to select it, and that's a bit of a pain.

  7. #7
    New Lounger
    Join Date
    May 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto Select (Access 97)

    Speaking of the default value, if it is possible to set the default to...say...the first value in the list box, (which would actually be the only value) that would work great. But it can't be a constant default, it would have to select the number that shows up in the list box after the combo box is selected.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Auto Select (Access 97)

    If the list box only has one item, why don't you use a text box? You can put the appropriate value into it in the AfterUpdate event of the combo box.
    If you still prefer the list box, you could set the value of the list box in that event, something like (this is air code):

    lbxSomething = lbxSomething.ItemData(0)

    The ItemData property contains all items in the listbox, zero-based, so ItemData(0) is the first (and here only) item.

  9. #9
    New Lounger
    Join Date
    May 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto Select (Access 97)

    I didn't use a text box, because it doesn't allow me to select a row source. This worked though (lbxSomething = lbxSomething.ItemData(0)). Thank you very much.
    In case you hadn't guessed, I'm fairly new to databases, but I'm learning every day.

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

    Re: Auto Select (Access 97)

    Sorry, but you lost me. The purpose of relational design is to insert the value you need to relate to other records, not to insert the related valued in the same record as the key. A combobox can only be bound on a single column. The other columns can be written to other fields using code, but it very bad design to do it that way. I don't see why inserting the current value requires two fields to be written. <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    Charlotte

  11. #11
    New Lounger
    Join Date
    May 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto Select (Access 97)

    I may have gone at it backwards. This is my first database, and I sort of learned it as I went.
    In one table, I have the related information, such as tool #, pieces produced per hour, etc. The combo box on the form selects the tool #, and automatically selects the pieces per hours for that tool. Then both numbers are written to a different table that includes other information about each time that tool runs such as run time, down time, good parts produced, etc. The information in this table is used for efficiency reports, run time reports, etc. If we wish to run a tool specific efficiency report, the tool number must be in that record, along with the expected pieces per hour, run time, and actual good parts.
    Hopefully, that's a little more clear. The code that HansV suggested works, and it now does what I want it to do, but if you have suggestions of how to do it more efficiently, they would be welcomed.
    If you wish, I can email the relevant form with the related tables. I was going to attach it here, but I couldn't get it down to 100k and still have enough left for you to understand what it's doing.

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

    Re: Auto Select (Access 97)

    It depends on what you're actually doing with the data. If your table with the related information has static data about a particular tool #, such as the capacity, then the customary way to handle it would be to insert the key pointing to that tool # into the data table that contains the runs. You could then join the two tables together in a query when you needed the rest of the data related to that tool number.
    Charlotte

Posting Permissions

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