Update or CancelUpdate without AddNew or Edit - ?

G

Guest

Hello,

I'm using Access 2003. I a typical data-entry form with a ComboBox at the
top used to select the frist/last name of a person, and then the form fills
up with their data.

I noticed this strange behavior: If I select a person, say "Joe Smith", by
clicking on his name in the ComboBox, the form fills with his data, no
problem. Then if I open the drop-down again and click "Joe Smith" for the
second time, I get this error:

Update or CancelUpdate without AddNew or Edit

And here is the code:

Private Sub NameComboBox_AfterUpdate()

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = '" & Me![NameComboBox] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark <--- this sometimes errors

rs.Close
Set rs = Nothing

If <some criteria> Then
Me.SomeControl = "" <--- this line sometimes errors
End If

End Sub


Any ideas?

Thanks,

-Scott
 
G

Guest

Scott,

First, you should test for a match or not using rs.nomatch to make sure you
have a match before you try to use the bookmark method. If your combo box is
pulled from the same recordset as the form, this should not be a problem, but
since you don't have any error trapping, use it anyway.

rs.findFirst ...
if rs.nomatch then
msgbox "No matching record to " & me.NameComboBox
else
me.bookmark = rs.bookmark
end if

***
What type of control is me.SomeControl? if it is not a textbox or a combo
box, I don't think you can set the value to an empty string.

HTH
Dale
 
G

Guest

Dale,

My combobox is driven from the same record source that the form is bound to,
but I still appreciate your advice on rs.nomatch.

It is a textbox control, so setting to an empty string is not the problem.
This behavior ONLY happens when I click on the same person twice in the
combobox.

Any other ideas?

-Scott

Dale Fye said:
Scott,

First, you should test for a match or not using rs.nomatch to make sure you
have a match before you try to use the bookmark method. If your combo box is
pulled from the same recordset as the form, this should not be a problem, but
since you don't have any error trapping, use it anyway.

rs.findFirst ...
if rs.nomatch then
msgbox "No matching record to " & me.NameComboBox
else
me.bookmark = rs.bookmark
end if

***
What type of control is me.SomeControl? if it is not a textbox or a combo
box, I don't think you can set the value to an empty string.

HTH
Dale

--
Email address is not valid.
Please reply to newsgroup only.


scottydel said:
Hello,

I'm using Access 2003. I a typical data-entry form with a ComboBox at the
top used to select the frist/last name of a person, and then the form fills
up with their data.

I noticed this strange behavior: If I select a person, say "Joe Smith", by
clicking on his name in the ComboBox, the form fills with his data, no
problem. Then if I open the drop-down again and click "Joe Smith" for the
second time, I get this error:

Update or CancelUpdate without AddNew or Edit

And here is the code:

Private Sub NameComboBox_AfterUpdate()

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = '" & Me![NameComboBox] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark <--- this sometimes errors

rs.Close
Set rs = Nothing

If <some criteria> Then
Me.SomeControl = "" <--- this line sometimes errors
End If

End Sub


Any ideas?

Thanks,

-Scott
 

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