Hi Again - This is sort of a follow-up to my General Form and command button design question, but it's a new problem now. I was able to get a form to open based on a drop-down menu selecction with the following code: -
Private Sub Command7_Click()
-
On Error GoTo Err_Command7_Click
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = Me![Study]
-
-
stLinkCriteria = "[WhichStudyID]=" & Me![WhichStudyID]
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
-
Exit_Command7_Click:
-
Exit Sub
-
-
Err_Command7_Click:
-
MsgBox Err.Description
-
Resume Exit_Command7_Click
-
End Sub
-
This worked successfully to open the form I select from the drop-down menu. However, it does not open it to the correct record. I have TblDemographics to tblWhichStudy through DemographID (pk of tblDemographics), then I have TblWhichStudy to TblStudyA, StudyB, StudyC, etc. through WhichStudyID (primarykey of tblWhichStudy). Form WhichStudy is a subform on Form Demographics. Form StudyA, etc., is a separate form opened through the command button. DemographID successfully gets pulled into tblWhichStudy, but neither WhichStudyID nor DemographID get pulled into StudyA table. I have the row source for each of these values in StudyA table as:
SELECT [Demographics Table].DemographID FROM [Demographics Table];
and
SELECT [WhichStudy Table].WhichStudyID FROM [WhichStudy Table];
Can anyone identify what I am setting up wrong? Thank you!
8 1280
Hi Again - This is sort of a follow-up to my General Form and command button design question, but it's a new problem now. I was able to get a form to open based on a drop-down menu selecction with the following code: -
Private Sub Command7_Click()
-
On Error GoTo Err_Command7_Click
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = Me![Study]
-
-
stLinkCriteria = "[WhichStudyID]=" & Me![WhichStudyID]
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
-
Exit_Command7_Click:
-
Exit Sub
-
-
Err_Command7_Click:
-
MsgBox Err.Description
-
Resume Exit_Command7_Click
-
End Sub
-
This worked successfully to open the form I select from the drop-down menu. However, it does not open it to the correct record. I have TblDemographics to tblWhichStudy through DemographID (pk of tblDemographics), then I have TblWhichStudy to TblStudyA, StudyB, StudyC, etc. through WhichStudyID (primarykey of tblWhichStudy). Form WhichStudy is a subform on Form Demographics. Form StudyA, etc., is a separate form opened through the command button. DemographID successfully gets pulled into tblWhichStudy, but neither WhichStudyID nor DemographID get pulled into StudyA table. I have the row source for each of these values in StudyA table as:
SELECT [Demographics Table].DemographID FROM [Demographics Table];
and
SELECT [WhichStudy Table].WhichStudyID FROM [WhichStudy Table];
Can anyone identify what I am setting up wrong? Thank you!
You must Add the WHERE statement in your SELECT Statement
ex:
SELECT [WhichStudy Table].WhichStudyID FROM [WhichStudy Table] WHERE [WhichStudy Table]![DemographID]=[Demographics Table]![DemographID]
Thank you! That worked :)
Thank you! That worked :)
No problem. Glad it worked.
Hi again,
I apologize, I jumped the gun there - it did not actually work. What it does it prompt me for the value that I specified in the Where condition. For example, I have DemographID set up as:
SELECT [WhichStudy Table].DemographID FROM [WhichStudy Table] WHERE [WhichStudy Table]!DemographID=[Demographics Table]!DemographID;
When I re-open the form, it does not go to the specific record. So I went to the table to look at what's in there, and neitehr DemographID nor WhichStudyID carried over. So I clicked on the DemographID field and it prompts me for [Demographics Table]!DemographID
The same thing happens for WhichstudyID, which I have set up as:
SELECT [WhichStudy Table].WhichStudyID FROM [WhichStudy Table] WHERE [WhichStudy Table]!DemographID=[Demographics Table]!DemographID;
Again, the relationship is set up that the WhichStudyID is the primary Key in the whichStudy Table, and the foreign key in the StudyA table, in a one-to-one relationship. When I tried it last week I think I entered a value in the parameter box, and then of course it opened correctly. But how do I get it to automatically read the WhichStudyID and DemographID from the previous form? Could you explain how the above statement is supposed to work (the logic behind it), then i might be able to figure out how to make the table know which value to pull in.
Thanks again, I really appreciate the assistance!
Hi again,
I apologize, I jumped the gun there - it did not actually work. What it does it prompt me for the value that I specified in the Where condition. For example, I have DemographID set up as:
SELECT [WhichStudy Table].DemographID FROM [WhichStudy Table] WHERE [WhichStudy Table]!DemographID=[Demographics Table]!DemographID;
When I re-open the form, it does not go to the specific record. So I went to the table to look at what's in there, and neitehr DemographID nor WhichStudyID carried over. So I clicked on the DemographID field and it prompts me for [Demographics Table]!DemographID
The same thing happens for WhichstudyID, which I have set up as:
SELECT [WhichStudy Table].WhichStudyID FROM [WhichStudy Table] WHERE [WhichStudy Table]!DemographID=[Demographics Table]!DemographID;
Again, the relationship is set up that the WhichStudyID is the primary Key in the whichStudy Table, and the foreign key in the StudyA table, in a one-to-one relationship. When I tried it last week I think I entered a value in the parameter box, and then of course it opened correctly. But how do I get it to automatically read the WhichStudyID and DemographID from the previous form? Could you explain how the above statement is supposed to work (the logic behind it), then i might be able to figure out how to make the table know which value to pull in.
Thanks again, I really appreciate the assistance!
You just have to specify the WHERE condition to be bound by the form instead of the table.
ex: WHERE DemographID = Forms![Name Of the Form]![Name of the control for the DemographID]
Thanks for the reply. When you say "[Name of the control for the DemographID]" - does that mean that demographID has to be a field on the form? DemographID is in all tables, as a primary key in the Demographics Table, and then a foreign key in all others, but it does not actually appear on the forms. Am I misunderstanding your comment?
Thanks again!
You just have to specify the WHERE condition to be bound by the form instead of the table.
ex: WHERE DemographID = Forms![Name Of the Form]![Name of the control for the DemographID]
Ok, 1 success, 1 failure remains...
I got the form to open to the correct record by using the OpenArgs property, as follows: -
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
-
Previously I was using it in the Where Condition property and it did not open. So I understand why it's opening now. I still, however, cannot get the WhichStudyID to filter down into the table for StudyA. Could you please clarify why the OpenArgs property opens the form to the correct record through WhichStudyID, but then WhichStudyID doesn't appear in the table for that form? I tried using the following:
SELECT [WhichStudy Table].WhichStudyID FROM [WhichStudy Table] WHERE [WhichStudy Table]![DemographID]=[Demographics Table]![DemographID]
I'm having a hard time understanding exactly what this does though - if neither WhichStudyID nor DemographID are being pulled into StudyA table, how would the above WHERE statement work? Why is a Where statement needed at all?
Thank you again for your help, I appreciate the explanations as I try to understand what it is I'm coding :)
Thanks for the reply. When you say "[Name of the control for the DemographID]" - does that mean that demographID has to be a field on the form? DemographID is in all tables, as a primary key in the Demographics Table, and then a foreign key in all others, but it does not actually appear on the forms. Am I misunderstanding your comment?
Thanks again!
If you want to open the other form and go straight to that record currently showing in the form, you have to set the where condition or the open arguments to match the primary key of that record in the 1st form. When I say [Name of the Control of the DemographID], yes I mean it is a control on the form. You need to have that control on the form. If you don't want to show it, just change it's visible property set to NO / False, but it must be present on that form. (even if you can only see it in the design view of the form).
Again,
if you want to open another (2nd) form and go to that record which is related to the record in the 1st form using the Primary key of that record, which I believe is teh DemographID. got it? :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John Simmons |
last post by:
How is it that even though I have the column "username" in my database set
as a Primary key, using my PHP script to add new users to the database works
without any errors even when signing up using...
|
by: Ghulam Farid |
last post by:
Hi
i have a table with primary key defined on col1 and col2. now i want to
have col3 also included in primary key. when i alter the table it gives
me error for duplicate rows. there is an option...
|
by: Mavis Tilden |
last post by:
Hi all,
So I've been reading the newsgroups, and reading a few books trying to learn
SQL and SQL Server 2000. The books tell me I need a Primary Key, and that
every table should have one. I know...
|
by: 101 |
last post by:
Taking a course on SQL. They are saying you can get better performance by
having multiple files for a group.
They then graphically show an example of "Primary" with multiple data files.
I have...
|
by: serge |
last post by:
I ran into a table that is used a lot. Well less than
100,000 records. Maybe not a lot of records but i believe
this table is used often. The table has 26 fields, 9 indexes
but no Primary Key at...
|
by: shenanwei |
last post by:
I have a primary server and backup server located in different physical
sites.
The primary server is live and ship logs to backup site every 5
minutes.
The primary server is being full online...
|
by: misscrf |
last post by:
Ok I have 2 issues.
1) I have a main candidate form with 2 subforms on a tab control:
http://www.geocities.com/misscrf/images/contactcontinouscheckbox.jpg
I have been encouraged to add these...
|
by: Thomas A. Anderson |
last post by:
I am a bit confused in creating a composite primary key. I have three table
with two of the tables containing primary keys. I have two of the tables
(each with a primary key) having one to many...
|
by: Challenge |
last post by:
Hi,
I got error, SQL1768N Unable to start HADR. Reason code = "7", when I
tried to start hadr primary database. Here are the hadr configuration
of my primary db:
HADR database role ...
|
by: Peter |
last post by:
I am interested in informed feedback on the use of Constraints, Primary Keys
and Unique.
The following SQL statement creates a Bands tables for a database of
bookings Bands into Venues, where the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
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...
| |