Requery and return to same record

  • Thread starter Thread starter Mary
  • Start date Start date
M

Mary

When I use me.requery my form returns to the first record
in the table its bound to. I wish it to remain at the
record being viewed.

How do I accomplish this?

Note that I use a combo box to select the record to view;
control name is [cboCustID].

I will appreciate any help. I'm sure this has
applications elsewhere in my database.

Thanks,
Mary
 
Save the primary key value, and FindFirst after the Requery.

This kind of thing:

Dim varID as Variant

If Me.Dirty Then Me.Dirty = False 'Save any edits.
varID = Me.CustID 'Remember the primary key value.
Me.Requery
If IsNull(varID) Then 'Must have been a new record.
RunCommand acCmdRecordsGotoNew
Else
With Me.RecordsetClone
.FindFirst "[CustID] = " & varID
If .NoMatch Then
Beep
Else
Me.Bookmark = .Bookmark
End If
End With
End If

Note: If CustID is a Text type field (not a Number type field), you need
extra quotes:
.FindFirst "[CustID] = """ & varID & """"
 
Perfect!

Thanks for the help.

Mary



-----Original Message-----
Save the primary key value, and FindFirst after the Requery.

This kind of thing:

Dim varID as Variant

If Me.Dirty Then Me.Dirty = False 'Save any edits.
varID = Me.CustID 'Remember the primary key value.
Me.Requery
If IsNull(varID) Then 'Must have been a new record.
RunCommand acCmdRecordsGotoNew
Else
With Me.RecordsetClone
.FindFirst "[CustID] = " & varID
If .NoMatch Then
Beep
Else
Me.Bookmark = .Bookmark
End If
End With
End If

Note: If CustID is a Text type field (not a Number type field), you need
extra quotes:
.FindFirst "[CustID] = """ & varID & """"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

When I use me.requery my form returns to the first record
in the table its bound to. I wish it to remain at the
record being viewed.

How do I accomplish this?

Note that I use a combo box to select the record to view;
control name is [cboCustID].

I will appreciate any help. I'm sure this has
applications elsewhere in my database.

Thanks,
Mary


.
 
Back
Top