473,467 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Add records to a subform

2 New Member
I have a continuous form which displays a list of flower seed lot records. The name of this form is "frmBreckenridgeData." Each seed lot record has a check box control – “SelectRedord” - which can be selected or deselected. This form contains a command button which opens a work order form - “frmGerminationTestWorkOrder" - in Add Data Mode. The frmGerminationTestWorkOrder work order form has a sub form - "fsubWorkOrderData."

The frmGerminationTestWorkOrder work order form contains a command button – “cmdAddRecord” - which creates a new work order record by generating an auto number in the “GermTestWorkOrderID” control on the form.

When I click on the cmdAddRecord command button, I would also like to use code to add seed lot record(s) to the fsubWorkOrderData sub form where the frmBreckenridgeData form “SelectRecord” checkbox control = true.

I’m assuming that I need to do this by using code that creates a record set but I have no idea how to do this. I am fairly new to MS Access VBA programming so please be gentle.

Thanks.
Jan 15 '10 #1
4 2986
ADezii
8,834 Recognized Expert Expert
We would need additional information such as:
  1. What is the Record Source for the Main Form?
  2. What is the Record Source for the Sub-Form?
  3. What are the linking Fields for the Main/Sub-Form?
  4. Where are you deriving the data for the newly added Record in the Sub-Form?
  5. What are the Control Names on the Main Sub-Form, and what Fields are they 'Bound' to?
  6. etc.
Jan 15 '10 #2
rclandreth
2 New Member
ADezii,

I'm grateful to have a response to my question. I hope I can adequately answer your questions and provide you with enough detail:

1. Record Source for frmGerminationTestWorkOrder is GermTestWorkOrder table.

2. Record Source for fsubGerminationTestWorkOrderData (please note that I used the wrong sub-form name in my initial post) is GermTestWorkOrderData table.

3. Linking fields for Main/Sub-form is: Master Field = GermTestWorkOrderID (Primary Key in GermTestWorkOrder table) and Child Field = GermTestWorkOrderID.

4. Record Source for frmBreckenridgeData form is ztblBreckenridgeInventory table. I want to derive data for the sub-form from this temp table. The process I am trying to accomplish is to select specific flower seed lots to be germination tested. To do this, I select specific flower seed lot records on the frmBreckenridgeData form by clicking the [SelectRecord] control. The [SelectRecord] control is bound to the [SelectRecord] field on the ztblBreckenridgeInventory table. After selecting seed lots, the next step is to click on the cmdCreateWorkOrder command button control which opens the frmGerminationTestWorkOrder work order form in Add Data Mode. If I decide to proceed with creating a work order, I click on the cmdAddRecord command button control on the Work Order form and would like to add records to the work order subform. I want to add [ClassName], [ProductCode], and [LotCode] data from the ztblBreckenridgeInventory table to the germination test work order sub-form where the [SelectRecord] field = true in the ztblBreckenridgeData table.

5a. Control Names on frmBreckenridgeData form are: [SelectRecord] (this is a checkbox), [ClassName], [ProductCode], [LotCode]. These fields are bound to fields with same names in the ztblBreckeridgeInventory table.
5b. Control Names on frmGerminationTestWorkOrder form are: [GermTestWorkOrderID] (master field), [GermTestWorkOrderDate], and [KeyTestLocation]. These controls are bound to fields with the same names in the GermTestWorkOrder table. The [GermTestWorkOrderID] field in the table is the Primary Key.
5c. Control Names on the fsubGerminationTestWorkOrderData sub-form are: [GermTestWorkOrderID] (child field), [ClassName], [ProductCode], and [LotCode]. These controls are bound to fields with the same names in the GermTestWorkOrderData table.

I hope this is enough detail to help you understand my database and provide me with a clue as to how I can accomplish this. Thank you for your time.

RCL
Jan 15 '10 #3
ADezii
8,834 Recognized Expert Expert
Just give me a little time to get to it, I'm swamped at the moment.
Jan 15 '10 #4
ADezii
8,834 Recognized Expert Expert
RCL, this is one of those Threads that is very difficult to diagnose without the actual Database being in front of you, but I've made every effort to do so, especially since you were very detailed and meticulous in your replies.
  1. Pay special attention to the Comments, since they were strategically placed for very good reasons.
  2. I'm assuming that Code Execution is in the frmGerminationTestWorkOrder Form, thus the Me in certain code references.
  3. Remember, that you can never add Record(s) to a Linked Sub-Form unless a Record has been Added and Saved to the Parent first. The code partially checks for this.
  4. Much of the code is related to Comments and Error Checking, I suggest you leave these in tact.
  5. Any further questions, feel free to ask.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdTest_Click()
  2. On Error GoTo Err_cmdTest_Click
  3. Dim strSQL As String
  4. Dim lngID As Long
  5. Dim MyDB As DAO.Database
  6. Dim rst_1 As DAO.Recordset
  7. Dim rst_2 As DAO.Recordset
  8.  
  9. '***********************************************************************************
  10. 'Create a Recordset based on ztblBreckenridgeInventory, and return
  11. 'all Records where the [RecordSelect] Field = True
  12. strSQL = "SELECT * FROM ztblBreckenridgeInventory WHERE [SelectRecord] = True;"
  13.  
  14. Set MyDB = CurrentDb
  15. Set rst_1 = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly)
  16. '***********************************************************************************
  17.  
  18. '***********************************************************************************
  19. 'Create a Recordset representing the Record Source for the Sub-Form
  20. 'fsubGerminationTestWorkOrderData, namely GermTestWorkOrderData
  21. Set rst_2 = MyDB.OpenRecordset("GermTestWorkOrderData", dbOpenDynaset)
  22. '***********************************************************************************
  23.  
  24. '***********************************************************************************
  25. 'The Main Record MUST be Saved prior to adding a Record to the Sub-Form
  26. If Me.Dirty Then
  27.   Me.Dirty = False
  28. End If
  29. '***********************************************************************************
  30.  
  31. 'Extract the Linking ID for the Sub-Form from the Main Form (assume a LONG INTEGER)
  32. lngID = Me![GermTestWorkOrderID]
  33. '***********************************************************************************
  34.  
  35. With rst_1
  36.   Do While Not .EOF
  37.     rst_2.AddNew
  38.       'ADD Records from ztblBreckenridgeInventory WHERE [SelectRecord] = True to
  39.       'Sub-Form but Record in frmGerminationTestWorkOrder MUST be Saved prior to this
  40.       rst_2![ClassName] = ![ClassName]
  41.       rst_2![ProductCode] = ![ProductCode]
  42.       rst_2![LotCode] = ![LotCode]
  43.       rst_2![GermTestWorkOrderID] = lngID
  44.     rst_2.Update
  45.       .MoveNext
  46.   Loop
  47. End With
  48.  
  49. '***********************************************************************************
  50.  
  51. 'Requery the Sub-Form so that newly added Data will be immediately visible
  52. Me!fsubGerminationTestWorkOrderData.Requery
  53.  
  54. '***********************************************************************************
  55. 'Don't forget to Clean Up!
  56. rst_1.Close
  57. rst_2.Close
  58. Set rst_1 = Nothing
  59. Set rst_2 = Nothing
  60. '***********************************************************************************
  61.  
  62. Exit_cmdTest_Click:
  63.   Exit Sub
  64.  
  65. Err_cmdTest_Click:
  66.   MsgBox Err.Description, vbExclamation, "Error in cmdTest_Click()"
  67.     If Not rst_1 Is Nothing Then
  68.       rst_1.Close
  69.       Set rst_1 = Nothing
  70.     End If
  71.     If Not rst_2 Is Nothing Then
  72.       rst_2.Close
  73.       Set rst_2 = Nothing
  74.     End If
  75.   Resume Exit_cmdTest_Click
  76. End Sub
Jan 15 '10 #5

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

Similar topics

2
by: Deano | last post by:
Hi, I was just setting up a test system on a client's machine yesterday and as ever noticed a few problems. One that has thrown me is to do with the order of records in a subform (datasheet...
6
by: Matt K. | last post by:
Hi there, I have a form in an Access project that contains a subform which displays the results of a query of the style "select * from where = #a certain date#". In the main part of the form...
1
by: Mark | last post by:
This question refers to a main form with a continuous form subform. After an error occurs after entering several records in the subform, how can I delete all the data in the main form and all the...
1
by: phaddock4 | last post by:
Being fairly inexperienced at Access 2000, i've been reading many posts here for the last several days, and testing myself to find the best approach to do the following in A2K: SET UP: I have...
2
by: origin197511 | last post by:
Hello all... I'm having an issue with MSAccess 2000. I have a Form that holds records of my cartridge loads for a rifle and a subform that lists all groups that have been fired with that load. ...
10
by: Thelma Lubkin | last post by:
My form/subform combination that allows user to display 'ColorSet' records, move to other records via a selector, to add,delete, and edit them, and to manage the related 'Color' records from the...
4
by: tlyczko | last post by:
I have been looking on the NGs and I found this code to show if a subform has no records. I have this code in the MAIN form OnClose event: Private Sub btnClose_Click() '4/16/06 new code that...
4
by: sparks | last post by:
I am trying to fix a database that someone did about 4 yrs ago in access97. The main table just contains demographics and is on the main form of the database. It has a subform on a tab that...
3
by: paquer | last post by:
On my Main form I have a Command Button that opens a Subform in order to create a new Subform record. At this point I want the subform to show only the new record being created. Not all the...
0
by: jwbird | last post by:
I have a main form with multiple Subforms that are all displaying Datasheet information related to the Main form record. When I make changes/adds to the records(s) in the subform and tab to another...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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
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,...
0
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.