Adding data to a dro-down list

  • Thread starter Thread starter Martin Racette
  • Start date Start date
M

Martin Racette

Hi,

I have a database that the list is restricted to the data already in it, but I
also added the code for opening a form where I can add the new data to the list
if the data isn't there beforehand, but I must retype the data in the adding
form, and I'm wondering if there could be a way to add that data to the
specified field in the form that is opening to add the data to the list

--
Thank you in Advance

Merci a l'Avance

Martin
 
Use the AfterUpdate event of the form where you entered the lookup data to
Requery the combo on the previous form.

(You may need to undo the combo first.)
 
I don't quite understand what you mean by "undo the combo", and in which form
should I use the AFTERUPDATE event, is it on the one that has the combo box or
the one in which I can add data to the table to which the combo box is linked

--
Thank you in Advance

Merci a l'Avance

Martin
 
As an example:
- Form1.Combo1 has a RowSource of Table2
- Double-clicking Combo1 opens Form2, where you add a new record.

In Form2's Form_AfterUpdate event, use:
Forms!Form1.Combo1.Requery

Now if the cursor is still in Combo1 on Form1, and the user has added a
partial entry that is not in the list, Access will try to process the
NotInList event first before the requery can happen, so the code may fail.
To prevent that, do this:
With Forms!Form1.Combo1
If .Value = .OldValue Then
'do nothing
Else
.Undo
End If
.Requery
End With

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Martin Racette said:
I don't quite understand what you mean by "undo the combo", and in which form
should I use the AFTERUPDATE event, is it on the one that has the combo box or
the one in which I can add data to the table to which the combo box is linked

--
Thank you in Advance

Merci a l'Avance

Martin
list
 
Back
Top