Add a contractor and update form

  • Thread starter Thread starter Neal
  • Start date Start date
N

Neal

Hi there

We have a form that makes new records. When filling out the form, the users
select a supplier from a combo box. If there is a new supplier not in the
list, they double click on the combo box and it opens the New Supplier form
which they can then fill out and close when finished. It works fine, but
doesn't update the combo box with the newly created supplier. If they close
the form and reopen, it does.

How do I get the supplier combo box to show the new supplier when the
AddSupplier form is closed?

Thanks, Neal
 
Hi,
You have to requery the combo box.
If you requery from the form the combo is on:
Me.yourCombo.Requery

if from another form:
Forms!comboFormName!yourCombo.Requery
 
Thanks Dan, that works fine! The new value is now in the combo box.

I added Me.Combo.Requery to the OnGotFocus property of the combo so that
when they close the Add New from, it comes back to the combo box they were
on and requeries it.

One more thing that would make it nice for the users, would be to have the
new value selected by default. How can I do this?

Thanks, Neal
 
Hi,
I don't know anything about your combo so it's hard to say exactly.
I can show you how to pass a value back to your orginal form, be it the Id
of the new record or the text value, whatever you're adding.

In form 1, you can add a private module level variable (in the first section before any functions or subs)

Private strNew As String

Now add a property to your form

Public Property Let NewEntry(strIn As String)
strNew = strIn
End Property

Now in the close event of the AddNew form you can pass back whatever value you like
and set your combo equal to that value:

Forms!NameOfForm.NewEntry = 'whatever'

now after you requery, you just go:
Me.myCombo = strNew
 
Neal said:
Hi there

We have a form that makes new records. When filling out the form, the users
select a supplier from a combo box. If there is a new supplier not in the
list, they double click on the combo box and it opens the New Supplier form
which they can then fill out and close when finished. It works fine, but
doesn't update the combo box with the newly created supplier. If they close
the form and reopen, it does.

How do I get the supplier combo box to show the new supplier when the
AddSupplier form is closed?

You might like to have a look at the generic NotInList code that does
exactly what you want. You'll find it at:

http://www.datastrat.com/Code/NotInListCode.txt

--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
I get an error on this line...

Me.txtCustomerName.SelStart = Me.txtCustomerName.SelLength + 1

and it highlights .txtCustomerName.

Neal (-:
 
Back
Top