Recordset Clone using Autonumber

E

egibson

I'm using a combo box on my form to populate the entire form with the
information the user selects in the combo box. I am having trouble with my
code and it is not finding the record. I'm not sure why this is happening.
My ID is an autonumber and I'm not sure if this is why or not. Any help
would be greatly appreciated. Here is my code:

Private Sub Combo216_AfterUpdate()

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID]= " & Me![Combo216].Column(0) & ""
If Not rs.EOF Then
MsgBox "Record not found " & Me![Combo216].Column(0) & ""
Else
Me.Bookmark = rs.Bookmark
End If

Me!Combo216 = ""
Refresh

Me!Provider.SetFocus

End Sub
 
D

Dirk Goldgar

egibson said:
I'm using a combo box on my form to populate the entire form with the
information the user selects in the combo box. I am having trouble with
my
code and it is not finding the record. I'm not sure why this is
happening.
My ID is an autonumber and I'm not sure if this is why or not. Any help
would be greatly appreciated. Here is my code:

Private Sub Combo216_AfterUpdate()

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID]= " & Me![Combo216].Column(0) & ""
If Not rs.EOF Then
MsgBox "Record not found " & Me![Combo216].Column(0) & ""
Else
Me.Bookmark = rs.Bookmark
End If

Me!Combo216 = ""
Refresh

Me!Provider.SetFocus

End Sub


Your code testing for a non-match is incorrect. Do this:

Set rs = Me.RecordsetClone
rs.FindFirst "[ID]= " & Me![Combo216].Column(0)
If rs.NoMatch Then
MsgBox "Record not found " & Me![Combo216].Column(0)
Else
Me.Bookmark = rs.Bookmark
End If

The code generated by the wizard in Access 2000 and later versions,
referring to the EOF property, is simply incorrect; and on top of that, you
added a "Not" in there, reversing the meaning.
 
E

egibson

Oh wonderful! It works! Thanks so much for your help!

Dirk Goldgar said:
egibson said:
I'm using a combo box on my form to populate the entire form with the
information the user selects in the combo box. I am having trouble with
my
code and it is not finding the record. I'm not sure why this is
happening.
My ID is an autonumber and I'm not sure if this is why or not. Any help
would be greatly appreciated. Here is my code:

Private Sub Combo216_AfterUpdate()

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID]= " & Me![Combo216].Column(0) & ""
If Not rs.EOF Then
MsgBox "Record not found " & Me![Combo216].Column(0) & ""
Else
Me.Bookmark = rs.Bookmark
End If

Me!Combo216 = ""
Refresh

Me!Provider.SetFocus

End Sub


Your code testing for a non-match is incorrect. Do this:

Set rs = Me.RecordsetClone
rs.FindFirst "[ID]= " & Me![Combo216].Column(0)
If rs.NoMatch Then
MsgBox "Record not found " & Me![Combo216].Column(0)
Else
Me.Bookmark = rs.Bookmark
End If

The code generated by the wizard in Access 2000 and later versions,
referring to the EOF property, is simply incorrect; and on top of that, you
added a "Not" in there, reversing the meaning.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
M

Marshall Barton

egibson said:
I'm using a combo box on my form to populate the entire form with the
information the user selects in the combo box. I am having trouble with my
code and it is not finding the record. I'm not sure why this is happening.
My ID is an autonumber and I'm not sure if this is why or not. Any help
would be greatly appreciated. Here is my code:

Private Sub Combo216_AfterUpdate()

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID]= " & Me![Combo216].Column(0) & ""
If Not rs.EOF Then
MsgBox "Record not found " & Me![Combo216].Column(0) & ""
Else
Me.Bookmark = rs.Bookmark
End If

Me!Combo216 = ""
Refresh

Me!Provider.SetFocus

End Sub


The check for EOF is inappropriate. Try using something
more like:

Private Sub Combo216_AfterUpdate()

With Me.RecordsetClone
.FindFirst "[ID]= " & Me![Combo216].Column(0)
If .NoMatch Then
MsgBox "Record not found " &
Me![Combo216].Column(0) & ""
Else
Me.Bookmark = .Bookmark
End If
End With
Me!Combo216 = ""
Me!Provider.SetFocus

End Sub

Note that if the combo box's BoundColumn corresponds to the
ID field (i.e. it is 1), then you do not need to use
..Column(0)
 

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

Similar Threads

Textbox Filter 4
VBA for NotInList return to old record or BeforeUpdate value 2
RunTime Error 3070 8
Error 2147352567 2
Search combo box 2
Problem with Combo Box FindNext 7
runtime error 13 2
Error 2237 8

Top