473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

OpenArgs overwriting each record

12
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(foreign 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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command7_Click()
  2. On Error GoTo Err_Command7_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = Me![Study]
  8.     stLinkCriteria = Me.WhichStudyID
  9.  
  10.  
  11.    DoCmd.OpenForm stDocName, , , , , , stLinkCriteria
  12.  
  13.  
  14. Exit_Command7_Click:
  15.     Exit Sub
  16.  
  17. Err_Command7_Click:
  18.     MsgBox Err.Description
  19.     Resume Exit_Command7_Click
  20. End Sub
The form that it opens has the following code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Me.WhichStudyID = Me.OpenArgs
  3. End Sub
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
Mar 5 '08 #1
4 2141
Denburt
1,356 Expert 1GB
It sounds to me like you are editing the existing record as you stated unless i am mistaken you simply need to go to a new record to start adding the new info.

DoCmd.OpenForm stDocname, , , ,acFormAdd , , stLinkCriteria
Mar 6 '08 #2
QntmPg
12
Thanks for your reply - that sounds like a good idea, but when the form opens from the command button, I enter some data, then I try to close the form, I get the following error:

"You cannot add or change a record becuase a related record is required in table 'tblWhichStudy'"

If I look at tblWhichStudy, however, the record is there.

This is the same error message I get when I enter values for a record in the subform and then hit the button (if, alternatively, I enter values, go to a new subform section, ie a new record on the subform, then go back and hit the button for the first record, it does not give me that error)

Also, would adding acFormAdd mean that each time I hit the button, it goes to a new form, instead of to the record specified in the OpenArgs?

Thanks again - I think I must just be missing some crucial basic element that's holding this up!
Mar 7 '08 #3
Denburt
1,356 Expert 1GB
Thanks for your reply - that sounds like a good idea, but when the form opens from the command button, I enter some data, then I try to close the form, I get the following error:

"You cannot add or change a record becuase a related record is required in table 'tblWhichStudy'"

If I look at tblWhichStudy, however, the record is there.

This is the same error message I get when I enter values for a record in the subform and then hit the button (if, alternatively, I enter values, go to a new subform section, ie a new record on the subform, then go back and hit the button for the first record, it does not give me that error)

Also, would adding acFormAdd mean that each time I hit the button, it goes to a new form, instead of to the record specified in the OpenArgs?

Thanks again - I think I must just be missing some crucial basic element that's holding this up!
This definitely sounds like a structuring issue please define your tables and relationships for this form so I can try to help with this.

acFormAdd would take you to a new record not the one in the openargs. Are you trying to use openargs for filtering the form so you see 1 record in particular?
Mar 7 '08 #4
QntmPg
12
Hi Denburt,

Yes, I am trying to open a form to a specific record with OpenArgs, unless that record does not exist yet, in which case it needs to be a new record. Let me see if I can explain this better -

FormDemographics is bound to tblDemographics. FormWhichStudy is bound to tblWhichStudy, and is a continuous subform on FormDemographics. tblDemographics and tblWhichStudy are connected one to many through DemographID (PK of tblDemographics, FK of tblWhichStudy).

tblWhichStudy is connected to tblStudyX one to one through WhichStudyID (PK of tblWhichStudy, FK of tblStudyX). (there will be many tblStudyXs - tblStudyA, tblStudyB, etc., all connected the same way, so for simplicity I'm only working with one right now). FormStudyX is bound to tblStudyX (PK StudyXID).

Essentially a participant enters a study - demographic info (name, DOB, etc.) goes on FormDemographics. Each study they participate in (one person can participate in any number of studies) is listed on the continuous subform FormWhichStudy with the essential details about the participation - date they enrolled, sub-project they participated in. The purpose of the command button is to bring up a form specific to the study they participate in (StudyX) and enter details about that encounter - comments about the participant, whether certain tests were used, etc. So when a person participates in a study, that study gets entered on the subform FormWhichStudy and they get a WhichStudyID assigned, then I hit the command button to go to StudyX and I want that WhichStudyID to carry over to tblStudyX. The next time I hit that button on that record, I want to go specifically to FormStudyX with the record for that participant, defined by WhichStudyID.

I hope that has made sense, please let me know if I can clarify any of that. Thanks again for your help!
Mar 7 '08 #5

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

Similar topics

0
by: nic | last post by:
Hi I am currently having problems getting two forms to behave the way I want. I have two tables Student and Application, and their respective forms. (Tables)Student has StudentID (PK) & an...
11
by: Susan Bricker | last post by:
Hi. I am trying to open a form using 'openargs' parameter of the docmd.openform action. The problem is that I would like to pass the form some character (string) and integer data. My plan was to...
3
by: Tim Marshall | last post by:
I am almost certain that when I opened a form in A97 that openargs was available in that form's class module for the whole time the form was open. Apparantly this is not the case in A2003. From...
15
by: Tony Williams | last post by:
I have two forms, frma and frmb, both are for inputting new records and are based on a table, tblmonth, both have two controls, txtmonth and txtmonthlabela which are based on the fields in the...
3
by: Lyn | last post by:
Hi, I have been experiencing a problem passing a LIKE statement in the WHERE argument of a DoCmd.Openform statement. I have posted that issue separately. However, in an attempt to work around...
3
by: Jim Evans | last post by:
Using code and suggestions from an earkier thread in this group, I have created the following cond for the open event of a form I am opening from the button click event of another form. ...
2
by: shumaker | last post by:
I think the problem lies in my understanding(or misunderstanding) of the scope of references. 'Code from button click event on first form: Private Sub Ok_Click() Dim strRecordSource As String...
3
by: Tanis | last post by:
How do you pass more than one argument using OpenArgs?
3
by: angi35 | last post by:
I'm having a zero-length string problem... Hoping someone can help. (This is in Access 2000.) In FormA, I have a button that opens FormB with OpenArgs. In FormB, the OpenArgs are translated into...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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
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
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...

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.