bookmark bug access 2003

  • Thread starter timbits35 via AccessMonster.com
  • Start date
T

timbits35 via AccessMonster.com

Hi,

I am using Access 2003 11.8166.8221 SP3. Can anyone confirm or deny if the
bookmark bug has been fixed in this version? I am using the bookmark in a
form to locate records and even though I have not encountered any problems, I
wonder if I am safe. Here is my code. As well is it better to use On Click or
After Update.

Private Sub cbosearch_AfterUpdate()
' Find the record that matches the control.
On Error GoTo ProcError
Dim rs As Object

Set rs = Me.RecordsetClone
rs.FindFirst "[Lname] = '" & Me![cbosearch] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description
Resume ExitProc
End Sub

Thank you,
Liane
 
A

Allen Browne

Hasn't been seen for years; should be fine in this version.

Suggestions:
1. Explicitly save any edits in progress. This triggers any pending events,
and will avoid some weird (difficult to understand/debug) errors.

2. Test NoMatch rather than EOF after the FindFirst.

3. It may be better to be explicit about the kind of recordset you are
searching. In general, it's better to be as explicit as possible.

4. Consider letting the user know if there was no match.

5. Presumably cbosearch is unbound (so it's not trying to save a value.)

6. You might want to consider filtering rather than finding the first match
(since there could be multiple matches.)

Ignoring #6:

Private Sub cbosearch_AfterUpdate()
' Find the record that matches the control.
On Error GoTo ProcError
Dim rs As DAO.Recordset

If Me.Dirty Then Me.Dirty = False
Set rs = Me.RecordsetClone
rs.FindFirst "[Lname] = '" & Me![cbosearch] & "'"
If rs.NoMatch Then
MsgBox "Not found"
Else
Me.Bookmark = rs.Bookmark
End If
ExitProc:
Set rs = Nothing
Exit Sub

ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description
Resume ExitProc
End Sub
 
D

David W. Fenton

Suggestions:
1. Explicitly save any edits in progress. This triggers any
pending events, and will avoid some weird (difficult to
understand/debug) errors.

2. Test NoMatch rather than EOF after the FindFirst.

3. It may be better to be explicit about the kind of recordset you
are searching. In general, it's better to be as explicit as
possible.

4. Consider letting the user know if there was no match.

5. Presumably cbosearch is unbound (so it's not trying to save a
value.)

6. You might want to consider filtering rather than finding the
first match (since there could be multiple matches.)

Also note that the find combo wizard since A2000 writes really bad
code, much worse than the A97 and earlier wizards. I don't know why
MS decided to use the Recordset instead of the RecordsetClone for
this. It makes no sense to me at all.
 
D

David W. Fenton

Private Sub cbosearch_AfterUpdate()
' Find the record that matches the control.
On Error GoTo ProcError
Dim rs As DAO.Recordset

If Me.Dirty Then Me.Dirty = False
Set rs = Me.RecordsetClone
rs.FindFirst "[Lname] = '" & Me![cbosearch] & "'"
If rs.NoMatch Then
MsgBox "Not found"
Else
Me.Bookmark = rs.Bookmark
End If
ExitProc:
Set rs = Nothing
Exit Sub

ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description
Resume ExitProc
End Sub

Also, I think it makes much more sense to just use a WITH block, so
you don't have to have a recordset variable:

Private Sub cbosearch_AfterUpdate()
' Find the record that matches the control.
On Error GoTo ProcError

With Me.RecordsetClone
.FindFirst "[Lname] = '" & Me![cbosearch] & "'"
If .NoMatch Then
MsgBox "Not found"
Else
If Me.Dirty Then
Me.Dirty = False
End If
Me.Bookmark = .Bookmark
End If
End With

ExitProc:
Exit Sub

ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description
Resume ExitProc
End Sub

I've never quite understood assigning a recordset variable for an
object that already exists.

Also, I question the use of single quotes. If the name is "O'Connor"
you're in trouble.
 

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