1
votes

In recording Patient data, two of the elements required are Main Consultant and Other Consultant. A table called consultant_list stores ID, name, code and speciality. A combo allows the consultant name to be selected, with the control storing the ID for that consultant in a table as consultant_id. The selection automatically displays the consultant's code and speciality in the bound controls on the form, txtConsultantCode and txtSpeciality.

Problem comes with the other consultant. Additional bound controls for consultant code and speciality automatically complete with the data selected under consultant. So I used unbound controls txtOtherConsultantCode and txtOtherSpeciality and set the AfterUpdate event for cboOtherConsultant to do a DLookup() and fill in the values. Thought that worked fine until I discovered that although it fills in the values OK, the values entered for the current record are also filling in in any previous record on the form, leaving inconsistent data. Also if the other consultant name is cleared, the values in the unbound controls remain, so I wrote code on the LostFocus event to check if cboOtherConsultant is Null and if so to set the associated values to Null also, but of course that also impacts on the other records. Help!

1

1 Answers

0
votes

You described what normally happens with unbound controls on a continuous form. Since they're unbound, the controls aren't tied to the current record. However, you can tie them to the current record by using your DLookup() expressions as the Control Source properties for those controls. With that approach, the controls would no longer be unbound.

However, I'm not convinced this is the best approach. Seems to me your form's record source could be a query which joins in consultant_list. Then you wouldn't need DLookUp() expressions to pull in the values for txtOtherConsultantCode and txtOtherSpeciality; they would already be present in the form's record source. And you could set the properties for those 2 text boxes to Enabled = No and Locked = Yes so they will be display-only ... the user would change them by making a different selection in cboOtherConsultant.