Subform seleciton

S

SirPoonga

Can I do this?

Lets say I have a form witha subform. I select a record in the
subform and press a button. THe button does some action along with
refreshing the subforms rowsource. If I kept the ID of the selected
record is there a way to select it automatically after refreshing the
rowsource?
 
A

Andi Mayer

Can I do this?

Lets say I have a form witha subform. I select a record in the
subform and press a button. THe button does some action along with
refreshing the subforms rowsource. If I kept the ID of the selected
record is there a way to select it automatically after refreshing the
rowsource?

assuming ID is numerical

dim IDsave as long
IDSave=me!ID 'assuming ID is the ID-field
with me.recordsetclone
.findfirst "ID=" &IDsave
if not .nomatch then Me.bookmark=.bookmark
end with
 
M

[MVP] S.Clark

Using the Bookmark property of a recordset you can accomplish this. The
code for something similar to this

Lookup the Bookmark Property in VBA side of the Help file. They have a long
example there.
 
S

SirPoonga

Ok, bookmarks.

I followed the example bookmark code in Help. I don't have a FindFirst
for the recordset object.

Help's code:
Private Sub cmdFindContactName_Click()
Dim rst As adodb.Recordset, strCriteria As String
strCriteria = "[ContactName] Like '*" & InputBox("Enter the " _
& "first few letters of the name to find") & "*'"

Set rst = Me.RecordsetClone
rst.FindFirst strCriteria
If rst.NoMatch Then
MsgBox "No entry found"
Else
Me.Bookmark = rst.Bookmark
End If
End Sub
 
S

SirPoonga

Could this be part of it?
According the Help
"When a bound form is opened in Form view, each record is assigned a
unique bookmark. "

My subform is in datasheet view. Anyway to do what I want in datasheet
view?
 
D

Dirk Goldgar

SirPoonga said:
Ok, bookmarks.

I followed the example bookmark code in Help. I don't have a
FindFirst for the recordset object.

Help's code:
Private Sub cmdFindContactName_Click()
Dim rst As adodb.Recordset, strCriteria As String
strCriteria = "[ContactName] Like '*" & InputBox("Enter the " _
& "first few letters of the name to find") & "*'"

Set rst = Me.RecordsetClone
rst.FindFirst strCriteria
If rst.NoMatch Then
MsgBox "No entry found"
Else
Me.Bookmark = rst.Bookmark
End If
End Sub

Is your form's RecordseClone actually an ADODB recordset? Unless you're
working in an ADP, it's probably a DAO recordset.
 
S

SirPoonga

In the Help example which I am now basing this off of
"Dim rst As adodb.Recordset"

So I would say it is.
 
D

Dirk Goldgar

SirPoonga said:
In the Help example which I am now basing this off of
"Dim rst As adodb.Recordset"

So I would say it is.

But maybe you are basing it on an inappropriate help topic. Is your
database an .mdb file? If so, your form's RecordsetClone is almost
certainly a DAO recordset, not an ADODB recordset. The only way it
wouldn't be is if you used code to open an ADODB recordset and bind your
form to it.
 
Top