0
votes

I want to save data from a selected recordset field, but I just save the first record. (Vorname, db and rs are public variables) [Vorname] is the column name in the recordset. The query is showed in a subform.

The Code:

Set db = CurrentDb
Set rs = db.OpenRecordset("Kontaktabfrage", dbOpenDynaset)
Vorname = rs![Vorname]
Me.Refresh

I want to get the selected record. Example:

ID| Vorname
1   John
2   Will
3   Stan

When I select Will in the subform, the recordset gives me John, because he is the first record, but I want Will. How can I read out that property?

1

1 Answers

0
votes

Use the RecordsetClone of the form:

Set rs = Me.RecordsetClone
' or, if in a subform:
' Set rs = Me.SubformControlNAME.Form.RecordsetClone

' Position the recordset to match the current record of the form.
rs.Bookmark = Me.Bookmark
' or, if in a subform:
' rs.Bookmark = Me.SubformControlNAME.Form.Bookmark

Vorname = rs![Vorname].Value