Custom row source for combo box in continuous form in Access

后端 未结 13 2145
北恋
北恋 2020-12-06 01:34

I have searched around, and it seems that this is a limitation in MS Access, so I\'m wondering what creative solutions other have found to this puzzle.

If you have a

相关标签:
13条回答
  • 2020-12-06 02:05

    Disclaimer: I hate Access with a passion.

    Don't use continuous forms. They're a red herring for what you want to accomplish. Continuous forms is the same form repeated over and over with different data. It is already a kludge of Access's normal mode of operation as you can't have the same form opened multiple times. The behavior you are seeing is "as designed" in Access. Each of those ComboBox controls is actually the same control. You cannot affect one without affecting the others.

    Basically, what you have done here is run into the area where Access is no longer suitable for your project (but cannot ditch because it represents a large amount of work already).

    What seems to be the most likely course of action here is to fake it really well. Run a query against the data and then create the form elements programmatically based on the results. This is a fair amount of work as you will be duplicating a good bit of Access's data handling functionality yourself.

    Reply to Edit:
    But as they are, continuous forms cannot accomplish what you want. That's why I suggested faking out your own continuous forms, because continuous forms have real limitations in what they can do. Don't get so stuck on a particular implementation that you can't let go of it when it ceases to work.

    0 讨论(0)
  • 2020-12-06 02:07

    use continuous forms .. definitely. In fact you can build entire applications with great and intuitive user interface built on continuous forms. Don't listen to Toast!

    Your solution of listing all options available is the correct one. In fact there is no other clean solution. But you are wrong when you say that Acccess goes nuts. On a continuous form, you could see each line as an instance of the detail section, where the combobox is a property common to all instances of the detail section. You can update this property for all instances, but cannot set it for one specific instance. This is why Access MUST display the same data in the combobox for all records!

    If you need to accept only record-specific values in this combobox, please use the beforeUpdate event to add a control procedure. In case a new value cannot be accepted, you can cancel data update, bringing back the previous value in the field.

    You cannot set the limitToList property to 'No' where the linked data (the one that is stored in the control) is hidden. This is logical: how can the machine accept the input of a new line of data when the linked field (not visible) stays empty?

    0 讨论(0)
  • 2020-12-06 02:14

    I also hate Access, but you must play with the cards you are dealt. Continuous forms are a wonderful thing in Access, until you run into any sort of complexity as is commonly the case, like in this instance.

    Here is what I would do when faced with this situation (and I have implemented similar workarounds before):

    Place an UNBOUND combobox on the form. Then place a BOUND textBox for the field you want to edit.

    Make sure the combobox is hidden behind (NOT invisible, just hidden) behind the textBox.

    In the OnCurrent event fill the listBox with the necessary data. Go ahead and "Limit to list" it too.

    In the OnEnter or OnClick event of the textBox give the combobox focus. This will bring the combobox to the forefront. When focus leaves the combobox it will hide itself once more.

    In the AfterUpdate event of the combobox set the value of the textbox equal to the value of the combobox.

    Depending on your situation there may be some other details to work out, but that should more or less accomplish your goal without adding too much complexity.

    0 讨论(0)
  • 2020-12-06 02:14

    Use OnEnter event to populate the combo box, don't use a fixed rowsource.

    0 讨论(0)
  • 2020-12-06 02:16

    I don't think that Access continuous forms should be condemned at all, but I definitely believe that they should be avoided for EDITING DATA. They work great for lists, and give you substantially more formatting capabilities than a mere listbox (and are much easier to work with, too, though they don't allow multi-select, of course).

    If you want to use a continuous form for navigation to records for editing, use a subform displaying the detailed data for editing, and use the PK value from the subform for the link field. This can be done with a continuous form where you place a detail subform in the header or footer, linked on the PK of the table behind the continuous form.

    Or, if you are using a continuous form to display child data in a parent form, you can link the detail subform with a reference to the PK in the continuous subform, something like:

    [MySubForm].[Form]!MyID
    

    That would be the link master property, and MyID would be the link child property.

    0 讨论(0)
  • 2020-12-06 02:17

    You could also make the value of the combo box into an uneditable text field and then launch a pop-up/modal window to edit that value. However, if I was doing that, I might be inclined to edit the whole record in one of those windows.

    0 讨论(0)
提交回复
热议问题