Hello.
I’m new to writing VBA code but getting there thanks, for the most part, to the excellent advice on this site.
I trying to create the code which will allow all records from a subform to be copied and duplicated back in the original underlying table for that subform.
To give a bit more background, the main form contains records of individual ‘reports’ (held in table called CPG1) and the subform (CPG3_Subform) identifies the ‘milestones’ for each report (the data for which is held in a table called (CPG3). Each milestone (there could be several for each report) is referenced back to corresponding report via its unique ID .The datadase has a command button allowing users to copy a report, in order to an updated report based on it. And I would like this copy process to include the ‘milestones’ held against that ‘report’.
The code I have patched together so far is as follows (line 6-17 are simply included for reference purposes):
1. Private Sub Command28_Click ()
2. On Error GoTo Err_Command28_C lick
3. Dim var As Variant
4. Dim rst As Recordset
5. Dim PreRPT As Integer
6. 'This section duplicates the latest report held, setting rpt ref and current date.
7. Me.MaxCPG1_subf orm.Requery
8. PreRPT = [MaxCPG1_subform]![MaxOfRPTRef]
9. DoCmd.RunComman d acCmdSelectReco rd
10. DoCmd.RunComman d acCmdCopy
11. DoCmd.RunComman d acCmdRecordsGoT oNew
12. DoCmd.RunComman d acCmdSelectReco rd
13. DoCmd.RunComman d acCmdPaste
14. ReportDate.Valu e = Now()
15. RPTRef.Value = PreRPT + 1
16. Me!Combo8.Reque ry
17. Me.Combo8 = Me.CPG_NoteID
18. 'This section duplicates the milestones
19. Set rst = CurrentDb.OpenR ecordset("CPG3" , dbOpenDynaset)
20. For Each var In Me.CPG3_subform
21. rst.AddNew
22. rst!CPGID = CPG_NoteID.Valu e
23. rst!Scheme = CPG3_subform.Co lumn(2, var)
24. rst!Description = CPG3_subform.Co lumn(3, var)
25. rst.Update
26. Next
27. rst.Close
28. Set rst = Nothing
29. Exit_Command28_ Click:
30. Exit Sub
31. Err_Command28_C lick:
32. MsgBox Err.Description
33. Resume Exit_Command28_ Click
34. End Sub
Lines 19-28 are the bits causing the problem (the previous lines work fine to simply copy the report). I’m getting an error message "Method or data member not found".
If this has already been type of query has already been addressed, would mind please pointing me in the right direction. I appreciate I may be going off entirely down the wrong track. I would be most grateful for any suggestions
I’m new to writing VBA code but getting there thanks, for the most part, to the excellent advice on this site.
I trying to create the code which will allow all records from a subform to be copied and duplicated back in the original underlying table for that subform.
To give a bit more background, the main form contains records of individual ‘reports’ (held in table called CPG1) and the subform (CPG3_Subform) identifies the ‘milestones’ for each report (the data for which is held in a table called (CPG3). Each milestone (there could be several for each report) is referenced back to corresponding report via its unique ID .The datadase has a command button allowing users to copy a report, in order to an updated report based on it. And I would like this copy process to include the ‘milestones’ held against that ‘report’.
The code I have patched together so far is as follows (line 6-17 are simply included for reference purposes):
1. Private Sub Command28_Click ()
2. On Error GoTo Err_Command28_C lick
3. Dim var As Variant
4. Dim rst As Recordset
5. Dim PreRPT As Integer
6. 'This section duplicates the latest report held, setting rpt ref and current date.
7. Me.MaxCPG1_subf orm.Requery
8. PreRPT = [MaxCPG1_subform]![MaxOfRPTRef]
9. DoCmd.RunComman d acCmdSelectReco rd
10. DoCmd.RunComman d acCmdCopy
11. DoCmd.RunComman d acCmdRecordsGoT oNew
12. DoCmd.RunComman d acCmdSelectReco rd
13. DoCmd.RunComman d acCmdPaste
14. ReportDate.Valu e = Now()
15. RPTRef.Value = PreRPT + 1
16. Me!Combo8.Reque ry
17. Me.Combo8 = Me.CPG_NoteID
18. 'This section duplicates the milestones
19. Set rst = CurrentDb.OpenR ecordset("CPG3" , dbOpenDynaset)
20. For Each var In Me.CPG3_subform
21. rst.AddNew
22. rst!CPGID = CPG_NoteID.Valu e
23. rst!Scheme = CPG3_subform.Co lumn(2, var)
24. rst!Description = CPG3_subform.Co lumn(3, var)
25. rst.Update
26. Next
27. rst.Close
28. Set rst = Nothing
29. Exit_Command28_ Click:
30. Exit Sub
31. Err_Command28_C lick:
32. MsgBox Err.Description
33. Resume Exit_Command28_ Click
34. End Sub
Lines 19-28 are the bits causing the problem (the previous lines work fine to simply copy the report). I’m getting an error message "Method or data member not found".
If this has already been type of query has already been addressed, would mind please pointing me in the right direction. I appreciate I may be going off entirely down the wrong track. I would be most grateful for any suggestions
Comment