Hi all,
I have read through what I could find on previous questions regarding using the OpenArgs property, but I'm still not able to get my form to open correctly. I'm not sure exactly where the problem is, so I'll try to describe what I'm doing in as much detail as I can. Any help is greatly appreciated!
I am building a database in Access 2003 to keep track of who participates in a study in our lab, and what study/ies they participate in. There are three main tables:
tblDemographics
DemographID (PK)
Name, etc.
tblWhichStudy
WhichStudyID (PK)
DemographID(for eign key from tblDemographics )
Study
ProjectName
EnrolledDate, etc.
tblStudyX (there are multiple of these tables, each for a specific study)
StudyXID (PK)
WhichStudyID (foreign key from tblWhichStudy)
various details on that study encounter
tblDemograph and tblWhichStudy are connected One to Many (one person can participate in many studies). tblWhichStudy and tblStudyX are connected one to one (each StudyID will refer to only one set of specific enounter details for that study - note that a person can participate in a study of the same name multiple times, but each time will have a new WhichStudyID and separate study encounter details)
A participant's information is entered on the form Demographics. The WhichStudy form is a continuous subform on the Demographics form - this way you can open a participant's record and see a list of all the studies they have participated in. Each record on the WhichStudy subform has a command button that opens a new form, specific to the study selected from the Study field, and specific to the WhichStudyID, coded through an event procedure in the OnClick property of the command button:
The form that it opens has the following code:
The form opens, and does so correctly to the study specified in the drop-down box. But the record it opens is the last one that was edited. So if I have two records in tblWhichStudy, ie two entries on the WhichStudy subform, and I hit the command button for the first and enter encounter details, when I hit the command button for the second entry (which is the same study name as the first entry, so it opens the same formX, but a different WhichStudyID because it's a separate encounter detail), the form opens with the data from the first record. If I change the data, it then overwrites the data from the first record with the data from the second record.
I've also noticed that when I enter a record on the subform, then hit the button and enter details, the close the formX, I get the error: "You cannot add or change a record because a related record is required in table "tblWhichStudy" " - I don't know if this is related to the issues above, or if it is separate entirely (or if I'm not understanding how a subform works).
Any advice is welcome - please let me know if I have been unclear on any of the above or if you need more details. I've learned a lot from these forums and really apprecite the help!
QntmPg
I have read through what I could find on previous questions regarding using the OpenArgs property, but I'm still not able to get my form to open correctly. I'm not sure exactly where the problem is, so I'll try to describe what I'm doing in as much detail as I can. Any help is greatly appreciated!
I am building a database in Access 2003 to keep track of who participates in a study in our lab, and what study/ies they participate in. There are three main tables:
tblDemographics
DemographID (PK)
Name, etc.
tblWhichStudy
WhichStudyID (PK)
DemographID(for eign key from tblDemographics )
Study
ProjectName
EnrolledDate, etc.
tblStudyX (there are multiple of these tables, each for a specific study)
StudyXID (PK)
WhichStudyID (foreign key from tblWhichStudy)
various details on that study encounter
tblDemograph and tblWhichStudy are connected One to Many (one person can participate in many studies). tblWhichStudy and tblStudyX are connected one to one (each StudyID will refer to only one set of specific enounter details for that study - note that a person can participate in a study of the same name multiple times, but each time will have a new WhichStudyID and separate study encounter details)
A participant's information is entered on the form Demographics. The WhichStudy form is a continuous subform on the Demographics form - this way you can open a participant's record and see a list of all the studies they have participated in. Each record on the WhichStudy subform has a command button that opens a new form, specific to the study selected from the Study field, and specific to the WhichStudyID, coded through an event procedure in the OnClick property of the command button:
Code:
Private Sub Command7_Click()
On Error GoTo Err_Command7_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = Me![Study]
stLinkCriteria = Me.WhichStudyID
DoCmd.OpenForm stDocName, , , , , , stLinkCriteria
Exit_Command7_Click:
Exit Sub
Err_Command7_Click:
MsgBox Err.Description
Resume Exit_Command7_Click
End Sub
Code:
Private Sub Form_Load() Me.WhichStudyID = Me.OpenArgs End Sub
I've also noticed that when I enter a record on the subform, then hit the button and enter details, the close the formX, I get the error: "You cannot add or change a record because a related record is required in table "tblWhichStudy" " - I don't know if this is related to the issues above, or if it is separate entirely (or if I'm not understanding how a subform works).
Any advice is welcome - please let me know if I have been unclear on any of the above or if you need more details. I've learned a lot from these forums and really apprecite the help!
QntmPg
Comment