Error with updating combo box

Turbojohn

Registered User.
Local time
Today, 22:23
Joined
Aug 14, 2006
Messages
16
Hi,

I have a form with various fields, some of which are normal data entry fields, others dynamically updating combo boxes.

My first field is a date field which defaults to today's date, the field following this is a growing combo box which requires some narrative to be entered. I have set up this combo box so as when data is entered into the combo box, the combo box will store it, allowing that entry to be used again. I achieve this with the Got Focus property Me.Refresh.

An error occurs when the user wishes to change the date from the default to another date. When I tab to the narrative field, Access informs me that the error occurs with the Me.Refresh property of the narrative field. I want to keep this property to allow me to update the combo box entries but I can't keep allowing this error to occur.

Does anyone know how I could solve this problem/get around it?

Thanks
Turbojohn
 
What is the error?
Which objects Got_Focus event are you using?
 
cuttsy said:
What is the error?
Which objects Got_Focus event are you using?
The error is:

Run-time error '2001': You cancelled the previous operation

I use the Got_Focus event on the Narrative field to update the combo box if a new entry is made:

Private Sub Narrative_GotFocus()
Me.Refresh
End Sub
 
I'm a little confused as to why you need to refresh the form so I don't think I am being helpfull.

Would it work if you used the Lost_Focus instead?
 
cuttsy said:
I'm a little confused as to why you need to refresh the form so I don't think I am being helpfull.

Would it work if you used the Lost_Focus instead?

Thanks for your reply,

I am refreshing the form so that when a new entry is made by the user in a combo box, this value will be updated and stored by the combo box so that next time round, when a new record is entered, this new value will be available to be selected.

I gave Lost_Focus a go but the same error occured, but this time it occured after I entered a value in the narrative field.

Hope this makes sense.

Any ideas? I'm stumped on this one.

Thanks
Turbojohn
 
So you have a combo box where the 'limit to list' property is set to 'No' and you are allowing the users to type in a new value as well as select from the list.

If that is the case then it should work without having to refresh the form.
 
cuttsy said:
So you have a combo box where the 'limit to list' property is set to 'No' and you are allowing the users to type in a new value as well as select from the list.

If that is the case then it should work without having to refresh the form.

Thanks for your reply,

The limit to list property is set to 'No' and users are allowed to type in a new value or select from the list.

This works, but only if the user exits the form and then opens it again.

This approach does not allow the list to be updated dynamically.

I need a way of allowing the list to be updated dynamically which does not lead to errors.

Any ideas?

Thanks
Turbojohn
 
If you remove the refresh line of code does it work how you want it to for the first record that you enter?

But when you try to enter another record the value you put in the combo box is not in the list. Is that corroct or not?
 
cuttsy said:
If you remove the refresh line of code does it work how you want it to for the first record that you enter?

But when you try to enter another record the value you put in the combo box is not in the list. Is that corroct or not?

Yes, that is correct

Turbojohn
 
Okie dokie.

Try removeing the refresh code from the focus event and copy this into your code. This event is triggerd when you move records.

Hopefully you wont get the error.

Code:
Private Sub Form_Current()

    Me.Refresh
End Sub

If that doesn't work maybe you don't need to refresh the whole form maybe you just need to requery the combo box

Code:
Private Sub Form_Current()

    cboYourComboBox.Requery
End Sub
 
cuttsy said:
Okie dokie.

Try removeing the refresh code from the focus event and copy this into your code. This event is triggerd when you move records.

Hopefully you wont get the error.

Code:
Private Sub Form_Current()

    Me.Refresh
End Sub

If that doesn't work maybe you don't need to refresh the whole form maybe you just need to requery the combo box

Code:
Private Sub Form_Current()

    cboYourComboBox.Requery
End Sub

Thanks for your reply,

I tried the first approach with one of my forms and it appears to work perfectly!

Thank you! :D

I'll make sure it works fine for everything else and repost if i'm having any more difficulties.

Thanks again, much appreciated
Turbojohn
 
Quite alright.
I can't believe it took me so many posts to get my head round your problem. :rolleyes:
 

Users who are viewing this thread

Back
Top Bottom