By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,071 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

how to move to a specific record after the form is refreshed?

P: n/a
Hi, If I have a primary key, say orderID, after I refreshed the form,
how can i get to that record via VBA.
Thanks.

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 21 Jul 2005 13:20:18 -0700, "swingingming" <mi******@gmail.com>
wrote:

Something like this:
'Assuming a long integer PK
public sub FormMoveToValue(byval strFieldName as string, byval
lngValue as Long, byref frm as Form)
dim rs as dao.recordset
set rs=frm.recordsetclone
rs.findfirst strFieldName & "=" & lngValue
if not rs.nomatch then
frm.bookmark = rs.bookmark
end if
set rs = nothing
end sub

For example in the Northwind sample application, Order form, you could
call this using:
FormMoveToValue "OrderID", orderID, Me

-Tom.

Hi, If I have a primary key, say orderID, after I refreshed the form,
how can i get to that record via VBA.
Thanks.


Nov 13 '05 #2

P: n/a
swingingming wrote:
Hi, If I have a primary key, say orderID, after I refreshed the form,
how can i get to that record via VBA.


You mentioned "Refresh" - the .Refresh method only updates values in the current
recordset. It will not add or delete records to that recordset that were modified after
the recordset was instantiated. That is, a .Refresh will not show new records or remove
ones that were deleted from the recordset. You'll need a .Requery to do that.

The .Requery method will invalidate any Bookmarks.

You'll need to store a unique value from the record, do your .Requery, and then use the
saved unique value to navigate back to the associated record.

**Air Code**:

nKeyID = Me!yourKeyValue

Me.Requery

With Me.Recordsetclone
.FindFirst yourKeyValue & "=" & nKeyID
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With

--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.