Re-selecting the selected row?

G

Guest

I use pop-ups for many entry forms, popped up from a continuous form in the
background. I need to update the continuous form to reflect changes when the
user closes the window. However, when you call me.refresh, the selection
disappears.

Is there any way to avoid this? SelTop does not appear to work, at least
when I try it I always get 0 as the selection. I tried using the form's
bookmark, but this appears to work or not work at random, and causes errors
on older versions of Access.

Any secrets here?

Maury
 
D

Dirk Goldgar

Maury Markowitz said:
I use pop-ups for many entry forms, popped up from a continuous form
in the background. I need to update the continuous form to reflect
changes when the user closes the window. However, when you call
me.refresh, the selection disappears.

Is there any way to avoid this? SelTop does not appear to work, at
least when I try it I always get 0 as the selection. I tried using
the form's bookmark, but this appears to work or not work at random,
and causes errors on older versions of Access.

Any secrets here?

Maury

Do you need the formerly current record to be *selected*, or just made
current again? For the latter, the normal procedure is to save the
primary key of the current record, open your popup form in dialog mode
(so it suspends code execution on the calling form), and then when code
execution resumes, requery the form and use Me.Recordset.FindFirst (or
Me.RecordsetClone.FindFirst and bookmark synchronization) to relocate
the original record.

You said "me.refresh", but refreshing the current form shouldn't change
its recordset nor which record is current, so I'm assuming you meant
"requery".
 
G

Guest

Dirk Goldgar said:
Do you need the formerly current record to be *selected*, or just made
current again?

I guess just made current. I had thought about keeping the id in an ivar,
but always hate doing that. C'est la vie.
You said "me.refresh", but refreshing the current form shouldn't change
its recordset nor which record is current, so I'm assuming you meant
"requery".

No, actually. Here is the exact code...

Public Sub refreshFromPopup()
On Error GoTo NoBookmark
varBookmark = Me.Bookmark
Me.Refresh
Me.Bookmark = varBookmark
Exit Sub

On Error GoTo done
NoBookmark:
Me.Refresh
done:
End Sub
 
D

Dirk Goldgar

Maury Markowitz said:
I guess just made current. I had thought about keeping the id in an
ivar, but always hate doing that. C'est la vie.


No, actually. Here is the exact code...

Public Sub refreshFromPopup()
On Error GoTo NoBookmark
varBookmark = Me.Bookmark
Me.Refresh
Me.Bookmark = varBookmark
Exit Sub

On Error GoTo done
NoBookmark:
Me.Refresh
done:
End Sub

I don't understand why this code would be necessary. Refreshing a form
shouldn't change its current record. What are you doing in the popup
form? If I put a button on a form and set its Click event procedure to
....

Private Sub Command1_Click()
Me.Refresh
End Sub

.... clicking the button doesn't reposition the form, and the record that
was current remains current, even if I have deleted it using an external
process, so that the record shows #Deleted in all bound controls.
 
G

Guest

Dirk Goldgar said:
I don't understand why this code would be necessary.

In retrospect, neither do I. I removed it and left in the refresh and it
seems to be working. Hmmmm...

I'll have to try it on one of the older machines to see if maybe that's why
I did it in the first place.

Maury
 

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