G
Guest
An old problem, that I aired some time ago, has raised its head again
I have a table that lists aircraft registration numbers and other associated details. Each record contains a Boolean field entitled ‘Selected’. A form has a combo box bound to this table via a query that selects those registration numbers for which ‘Selected’ is true. A query, run prior to the opening of this form, dynamically determines which aircraft are currently available, and which are not, by setting ‘Selected’ true or false respectively for each of the records in the table. The combo box on the form thus only offers the currently selectable aircraft. That works just fine. The combo box options are not, however, limited to the list derived from the table. This allows the selection of an aircraft that does not currently feature in the ‘Selected’ list, by typing-in its registration number. (There are, needless to say, good reasons for wanting to do this on occasions.) If a non-listed aircraft is selected then two subsequent tests must be performed :â€
1. If, due perhaps to a typo, the entered registration number does not correspond to any aircraft listed in the table, whether selected or not, then an error must be flagged
2. If the entered registration number corresponds to a currently non-selected aircraft then the additional details relating to it must be separately retrieved. The code for this is not discussed here
An obvious, and simple, way to perform these tests seems to be to use DLookup to individually check all the registration numbers selected or entered in the combo box to determine whether they appear in the table to which the combo box is bound. This was done as follows:â€
Private Sub Aircraft_AfterUpdate(
Dim Selected_AC As Strin
Selected_AC = DLookup("Registration", "tbl_Aircraft", "Registration = " & Me![Aircraft]
....etc
....etc
End Su
Me![Aircraft] is the registration number currently displayed in the combo box. The theory is that if Selected_AC is Null then the entered registration number does not correspond to an aircraft in the table – an error condition. Conversely, if the registration number is valid, then a similar DLookup test could subsequently be run to determine whether the ‘Selected’ field, corresponding to that aircraft registration, is true. If not then the aircraft is listed in the table but does not feature in the current selectable list. The above sub fails on the first test, however, because of the old DLookup problem. Apparently because Me![Aircraft] is a combo box, DLookup does not work, yielding, instead, Run Time Error ‘2001’ : “You cancelled the previous operation.†This has happened on every other occasion that I have tried to use DLookup in this way and I am therefore forced to the conclusion that the DLookup syntax I have used is incorrect or that DLookup is unusable in this context. How can I get around this
I have a table that lists aircraft registration numbers and other associated details. Each record contains a Boolean field entitled ‘Selected’. A form has a combo box bound to this table via a query that selects those registration numbers for which ‘Selected’ is true. A query, run prior to the opening of this form, dynamically determines which aircraft are currently available, and which are not, by setting ‘Selected’ true or false respectively for each of the records in the table. The combo box on the form thus only offers the currently selectable aircraft. That works just fine. The combo box options are not, however, limited to the list derived from the table. This allows the selection of an aircraft that does not currently feature in the ‘Selected’ list, by typing-in its registration number. (There are, needless to say, good reasons for wanting to do this on occasions.) If a non-listed aircraft is selected then two subsequent tests must be performed :â€
1. If, due perhaps to a typo, the entered registration number does not correspond to any aircraft listed in the table, whether selected or not, then an error must be flagged
2. If the entered registration number corresponds to a currently non-selected aircraft then the additional details relating to it must be separately retrieved. The code for this is not discussed here
An obvious, and simple, way to perform these tests seems to be to use DLookup to individually check all the registration numbers selected or entered in the combo box to determine whether they appear in the table to which the combo box is bound. This was done as follows:â€
Private Sub Aircraft_AfterUpdate(
Dim Selected_AC As Strin
Selected_AC = DLookup("Registration", "tbl_Aircraft", "Registration = " & Me![Aircraft]
....etc
....etc
End Su
Me![Aircraft] is the registration number currently displayed in the combo box. The theory is that if Selected_AC is Null then the entered registration number does not correspond to an aircraft in the table – an error condition. Conversely, if the registration number is valid, then a similar DLookup test could subsequently be run to determine whether the ‘Selected’ field, corresponding to that aircraft registration, is true. If not then the aircraft is listed in the table but does not feature in the current selectable list. The above sub fails on the first test, however, because of the old DLookup problem. Apparently because Me![Aircraft] is a combo box, DLookup does not work, yielding, instead, Run Time Error ‘2001’ : “You cancelled the previous operation.†This has happened on every other occasion that I have tried to use DLookup in this way and I am therefore forced to the conclusion that the DLookup syntax I have used is incorrect or that DLookup is unusable in this context. How can I get around this