Hello,
I've reviewed a number of other posts on the topic of "OpenArgs" and other methods for passing data between forms when using command buttons, however I've been unable to resolve my issue and would appreciate any assistance you can provide.
Overview of relevant portions of DB Structure
I'm obligated to sanitize this a bit due to my business purpose, but I think the below should encompass the relevant table structure:
Forms in Use
I have a "Person Detail" form which can be filtered/scoped based on search terms users are looking for, no issues there. The Person Detail form lists the data provided from the relevant table, and then has a sub form which contains a datasheet with a summary of the "events" tied to that person.
I've been successfully able to create a VBA script which pops up a "Event Detail" form when a user clicks the ID number of an event listed in the datasheet sub form for each person. No issues here.
The Issue
The issue I'm having, is that in addition to allowing my users to view existing events by clicking the ID number in the Inquiries Datasheet sub form, I've also placed a command button on the "Person Detail" form entitled 'New Event'; The behavior I'd like to have occur is to have the 'Event Detail' form open, start a new record that can be populated by the user, but have the "FK_Person" field/control already be populated to the Person the user was viewing on the "Person Detail" page.
I'd like to do this, because the DB will eventually have hundreds of users and each of those users may have multiple events; I'd like to avoid having to make my data entry users select the person associated with a new event each time they add an event, since they'll only be able to add new events while looking at an existing person.
What I've Tried So Far
I've found multiple posts about the "OpenArgs" method that is part of the DoCmd.OpenForm function. I've added the following code to my "Person Detail" Class Object:
Then, in the Class Object for the "Event Detail", I have the following:
I'm able to see in the immediate window that the argument IS getting passed to the new form, however depending on how I structure the code, I get various errors about either not being able to edit the field; or if I put the "Me.txtSubID" control ID in the place of the actual field, I get an error about needing to commit the record before being able to update it.
I've tried just about every combination of field and/or control ID, and I've tried some other blocks of code that I've found in similar questions, all to no avail, I'm unable to essentially "set" the FK_Person ID field at the time of prompting the user to create a new event.
Any insight would be appreciated!
I've reviewed a number of other posts on the topic of "OpenArgs" and other methods for passing data between forms when using command buttons, however I've been unable to resolve my issue and would appreciate any assistance you can provide.
Overview of relevant portions of DB Structure
I'm obligated to sanitize this a bit due to my business purpose, but I think the below should encompass the relevant table structure:
Code:
TABLE: tblPerson
ID (autonumber)
FK_Employer (Foreign Key to an employers table)
Person_Last (Var)
Person_First (Var)
Person_Title (Var)
Person_Flag1 (T/F)
Person_Flag2 (T/F)
Person_DateAdded (Date)
Person_Summary (LongText)
TABLE: tblEvent
ID
FK_Person (FK for the Person Table)
. . .
Other Fields
Forms in Use
I have a "Person Detail" form which can be filtered/scoped based on search terms users are looking for, no issues there. The Person Detail form lists the data provided from the relevant table, and then has a sub form which contains a datasheet with a summary of the "events" tied to that person.
I've been successfully able to create a VBA script which pops up a "Event Detail" form when a user clicks the ID number of an event listed in the datasheet sub form for each person. No issues here.
The Issue
The issue I'm having, is that in addition to allowing my users to view existing events by clicking the ID number in the Inquiries Datasheet sub form, I've also placed a command button on the "Person Detail" form entitled 'New Event'; The behavior I'd like to have occur is to have the 'Event Detail' form open, start a new record that can be populated by the user, but have the "FK_Person" field/control already be populated to the Person the user was viewing on the "Person Detail" page.
I'd like to do this, because the DB will eventually have hundreds of users and each of those users may have multiple events; I'd like to avoid having to make my data entry users select the person associated with a new event each time they add an event, since they'll only be able to add new events while looking at an existing person.
What I've Tried So Far
I've found multiple posts about the "OpenArgs" method that is part of the DoCmd.OpenForm function. I've added the following code to my "Person Detail" Class Object:
Code:
Private Sub btnNewEvent_Click()
Dim curRecord As Integer
curRecord = Me.ID
DoCmd.OpenForm "frmEventDetail", acNormal, , , acFormAdd, acWindowNormal, curRecord
End Sub
Then, in the Class Object for the "Event Detail", I have the following:
Code:
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Debug.Print (Me.OpenArgs)
Me.FK_Person = Me.OpenArgs
End If
End Sub
I'm able to see in the immediate window that the argument IS getting passed to the new form, however depending on how I structure the code, I get various errors about either not being able to edit the field; or if I put the "Me.txtSubID" control ID in the place of the actual field, I get an error about needing to commit the record before being able to update it.
I've tried just about every combination of field and/or control ID, and I've tried some other blocks of code that I've found in similar questions, all to no avail, I'm unable to essentially "set" the FK_Person ID field at the time of prompting the user to create a new event.
Any insight would be appreciated!
Last edited: