Updating combo box list

G

Guest

I've seen similar messages on this list, but I still seem to be missing something

On a BANK form I have a combo box called CountryCombo that includes a list of countries from a Country table. I have CountryCombo set to Limit-to-List and then for the event On Not in List, I call the following code

Private Sub COUNTRYCombo_NotInList(NewData As String, Response As Integer

UserAnswer = MsgBox("You have tried to enter a country not in the database. Do you which to add that country to the database?", vbYesNo, "Missing Country Warning"
If UserAnswer = vbYes The
DoCmd.OpenForm "Countries", , , , acFormAdd, acDialo
Els
Me.CountryCombo = Nul
End I
End Su

This code seems to work. But after I close the Countries form, the CountryCombo does not list the new country. I know I need to some how Requery the combo box, but I've tried several approaches. I usually get an error message after the Countries form closes and the focus returns to the BANK form--Error 2118 "You must save current field before you run requery action

For the Requery, I have tried CountryCombo.Requery and Me!CountryCombo.Requery and even Forms![Bank]![CountryCombo].Requer

A related question is where (what event) to put the request for the Requery code? Right now the requery code is called by the CountryCombo's On Got Focus event

Any help would be appreciated. Please be explicite!
 
A

Alphonse Giambrone

No need to requery, Access will handle it.
If UserAnswer = vbYes Then
DoCmd.OpenForm "Countries", , , , acFormAdd, acDialog
Response=acDataErrAdded
Else
Me.CountryCombo = Null
End If


--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us


Glen said:
I've seen similar messages on this list, but I still seem to be missing something.
Private Sub COUNTRYCombo_NotInList(NewData As String, Response As Integer)

UserAnswer = MsgBox("You have tried to enter a country not in the
database. Do you which to add that country to the database?", vbYesNo,
"Missing Country Warning")
If UserAnswer = vbYes Then
DoCmd.OpenForm "Countries", , , , acFormAdd, acDialog
Else
Me.CountryCombo = Null
End If
End Sub

This code seems to work. But after I close the Countries form, the
CountryCombo does not list the new country. I know I need to some how
Requery the combo box, but I've tried several approaches. I usually get an
error message after the Countries form closes and the focus returns to the
BANK form--Error 2118 "You must save current field before you run requery
action"
For the Requery, I have tried CountryCombo.Requery and
Me!CountryCombo.Requery and even Forms![Bank]![CountryCombo].Requery
A related question is where (what event) to put the request for the
Requery code? Right now the requery code is called by the CountryCombo's On
Got Focus event.
 
G

Guest

That was great--it worked

But can you explain in simple English what the following line actually does

Response=acDataErrAdde

I searched for acDataErrAdded in the Access help and found nothing
 
A

Alphonse Giambrone

It simply tells Access that the item has been added to the combo source, so
Access requeries the source itself.
Search help for the NotInList event for more info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top