473,505 Members | 13,925 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Merge multiple private sub procedures

1 New Member
Hi,

I am currently working on a form that will be used to update a table (tblAuditableEntitiesHistory). I have two private sub procedures that will need to be merged so that the table fields and records update simultaneously when the user selects the 'Add Record' button.

For the 1st prodecure (see Procedure 1 below), we needed to give users the option to enter a single Review Name in a textbox field but allow them to tie it to multiple entities. When multiple entities are selected in the 'Entity' listbox field, a new table record will be created for each selection where only the entity ID from the selection changes on each row. The entity ID field will be used as the foreign key to join to the Entity table for analysis. Procedure 1 is currently working.

Procedure 2 was created to allow users to select multiple cycles. When multiple cycles are selected in the 'InScopeCycles' listbox field, the entries should be saved as comma separated values in the 'Cycles_In_Scope' field within the table. Procedure 2 is currently not working.

Is there a way to merge Procedure 2 into Procedure 1 so that if the user selects multiple cycles and entities for a single review that all fields and records (if multiple entities are selected) are updated simultaneusly?

Procedure 1
Expand|Select|Wrap|Line Numbers
  1. Private Sub AddRecord_Click()
  2. On Error GoTo AddRecord_Click_Err
  3.  
  4. Dim MyDB As dao.Database
  5. Dim varItem As Variant
  6. Dim lst As ListBox
  7.  
  8. Set lst = Me![Entity]
  9.  
  10. Dim rst As dao.Recordset
  11. If lst.ItemsSelected.Count = 0 Or IsNull(Me![ReviewName]) Then
  12. MsgBox "You need to select an Entity and Review Name in order to proceed", vbExclamation, _
  13.           "Missing Data Input"
  14.             Exit Sub
  15. End If
  16.  
  17. Set MyDB = CurrentDb
  18. Set rst = MyDB.OpenRecordset("tblAuditableEntitiesHistory", dbOpenDynaset, dbAppendOnly)
  19.  
  20. With rst
  21. For Each varItem In lst.ItemsSelected
  22. .AddNew
  23. ![EntityID] = lst.ItemData(varItem)
  24. ![ReviewName] = Me![ReviewName]
  25. ![ReviewRating] = Me![ReviewRating]
  26. ![ReportNumber] = Me![ReportNo]
  27. ![Compliance_Assessment] = Me![ComplianceAssessment]
  28. ![Planned] = Me![Planned_Checkbox]
  29. ![ReportIssuanceDate] = Me![ReportsIssuanceDate]
  30. ![AuditPlanYear] = Me![AuditPlanYear]
  31. ![RiskRating] = Me![RiskRating]
  32. ![Comments] = Me![Comments]
  33. .Update
  34. Next varItem
  35. End With
  36.  
  37. rst.Close
  38. Set rst = Nothing
  39.  
  40. AddRecord_Click_Exit:
  41.     Exit Sub
  42.  
  43. AddRecord_Click_Err:
  44.     MsgBox Error$
  45.     Resume AddRecord_Click_Exit
  46.  
  47. End Sub
  48.  
  49. Procedure 2
  50. Private Sub InScopeCycles_Click()
  51.  
  52. Dim SelectedValues As String
  53. Dim frm As Form
  54. Dim varItem As Variant
  55. Dim lstItems As Control
  56. Set lstItems = Me!InScopeCycles
  57.  
  58. For Each varItem In lstItems.ItemsSelected
  59.     If SelectedValues > "" Then
  60.         SelectedValues = SelectedValues & ", " & lstItems.ItemData(varItem)
  61.     Else
  62.         SelectedValues = lstItems.ItemData(varItem)
  63.     End If
  64. Next varItem
  65. Me!Cycles_In_Scope = SelectedValues
  66.  
  67. End Sub
Aug 2 '15 #1
1 3276
jimatqsi
1,271 Recognized Expert Top Contributor
jharding,
Yes, of course the can be merged. These procedures you show are invoked by the click of a button (or other object - more about that below). They could just as easily be invoked by referencing the name like this:
Expand|Select|Wrap|Line Numbers
  1. AddRecord_Click
That would make the named procedure run without another click. So at the end of one procedure you could add that line of code to basically continue the processing in the second procedure.

For your AddRecord button, in the click event for that button you could do like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Addrecord_cmd_Click()
  2. AddRecord_Click     ' run first update procedure
  3. InScopeCycles_Click  ' run second update procedure
  4.  
  5. end sub
  6.  
Or you could copy the relevant code from each procedure and paste it into the AddRecord procedure in such a way that all you want to do is done. (Not really a good idea to duplicate code, though)

Now, about that Click event on your listbox object. That is going to end up running every time you click on the listbox. How will anybody ever select more than one entry in the list box? It's just going to run each time, doing one at a time.

You might be better off not using the listbox events to trigger that action. Maybe create a button to be used after all the selections are made.

Jim
Aug 7 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
596
by: Seshadri | last post by:
Dear All, My apologies if this is not the correct forum. Please redirect. I am a bit confused on where this kind of a question belongs. However I need help rather badly. I would like to merge two...
3
5168
by: svdh2 | last post by:
I have been looking at a problem the entire week in access, I have still not been able to find a solution. Hope that you could maybe tell where to look Concerns the link between Access and Word....
1
5681
by: Seshadri | last post by:
Dear All, My apologies if this is not the correct forum. I am a bit confused on where this kind of a question belongs. However I need help rather badly. I would like to merge two ASP.NET c#...
3
9520
by: Otto Carl Marte | last post by:
Hi, As I understand it, Declared Global Temporary Tables (DGTTs) have a scope that is session/connection based. Using the same connection, I have discovered that if I declare a DGTT in one...
3
3057
by: AccessThis | last post by:
Hi everyone, I’m fairly new to Access and VBA, but I have set up the following code to export all the records in my database to a word template (C:\Template.dot) with bookmarks (bkfield1,...
1
7747
by: Quish | last post by:
Hey I am creating a database application that is accessed through a .NET front end. What I want to do is run a SQL script that will create my DB, create my indexes and enforce my constraints...
1
2188
by: shimul | last post by:
Hi All, I would like to some code (VBA) that will merge multiple access Report to single PDF report. Thank you in advance. Shimul
0
1345
by: BarryM | last post by:
hey does anybody know how to merge any kind of two or several files and split them up. I know how to merge multiple image files but dont know to do it with any other type Dim sw As New...
3
3177
by: gelezniyden | last post by:
I have two stored procedures one for INSERT and second for Update and I'd like to merge them in one so could you please tell me which satement should I use for that ? CREATE PROCEDURE Tools...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.