Recordsetclone add new records to subform vba (1 Viewer)

jaryszek

Registered User.
Local time
Today, 03:29
Joined
Aug 25, 2016
Messages
756
Hi,

i am using code to populate subform:

Code:
Private Sub CmdCopyPaste_Click()

Set frm = Me.frmDisksSubform.Form
Dim rst As dao.Recordset
Dim frmSubName As String
Dim subFrm As Access.Form
Dim col As New Collection
    
    For Each varitem In Me.LstFormList.ItemsSelected
        frmSubName = Me.LstFormList.Column(0, varitem)
    Next varitem
    
    For Each varitem In Me.LstFieldsToAdd.ItemsSelected
        col.Add Me.LstFieldsToAdd.Column(0, varitem)
    Next varitem
    
    Set rst = fLoadRstWithSelected(frm)
    
    With rst
    .MoveFirst
        Do While Not .EOF
             With Me.Controls(frmSubName).Form.RecordsetClone
       [B]         For Each colItem In col
                .AddNew
                    !UsageIDFK = colItem
                .Update
              Next[/B]
            End With
'            Debug.Print rst.Fields(0)
            .MoveNext
        Loop
    End With

End Sub

and function :

Code:
Function fLoadRstWithSelected(pForm) As dao.Recordset
 
    Dim rst As dao.Recordset
 
    Set rst = pForm.Form.Recordset
    
    Set fLoadRstWithSelected = rst
    
End Function

For eACH record in subform with Server, Kind and Capacity
i am adding to other subform - UsageIDFK subform.
Code is working but after code - the changes are not saved.

Why?
Please help,
Best,
Jacek
 

Attachments

  • Screenshot_1.png
    Screenshot_1.png
    32.9 KB · Views: 131

Ranman256

Well-known member
Local time
Today, 06:29
Joined
Apr 9, 2015
Messages
4,337
you dont need to clone.
a recordset is a recordset.
or just run a query. No need for recordsets.
 

jaryszek

Registered User.
Local time
Today, 03:29
Joined
Aug 25, 2016
Messages
756
yes it is true.

i found the problem.

In order to loop between 2 forms and adding values to one of them you have to setfocus each time you are selecting new record in specific form.

Am i right?
Or maybe you have different ideas :)

Best,
Jacek
 

Users who are viewing this thread

Top Bottom