SOLVED

Getting a field from another form

%3CLINGO-SUB%20id%3D%22lingo-sub-2410850%22%20slang%3D%22en-US%22%3EGetting%20a%20field%20from%20another%20form%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2410850%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20Guys%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20survey%20attached%20to%20a%20user%20profile%2C%20and%20I%20am%20trying%20to%20connect%20it%20to%20a%20table%20with%20recommendations%20based%20on%20the%20user's%20input.%26nbsp%3B%20I%20am%20only%20just%20started%20learning%20about%20Access%203%20weeks%20ago%20and%20am%20really%20struggling%20on%20this.%26nbsp%3B%20The%20recommendations%20are%20attached%20to%20a%20form%20which%20I%20would%20like%20the%20user%20to%20be%20able%20to%20open%20in%20their%20profile.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20accomplish%20this%2C%20I%20am%20trying%20to%20pass%20the%20foreign%20key%20of%20the%20survey%20to%20the%20recommendations%20form%20to%20link%20the%20two.%26nbsp%3B%20I%20have%20attached%20some%20code%20of%20how%20I%20am%20trying%20to%20do%20this%2C%20but%20if%20anyone%20knows%20of%20a%20better%20alternative%2C%20I%20am%20all%20ears.%26nbsp%3B%20I%20have%20also%20attached%20the%20relationships%20table%20to%20give%20you%20an%20idea%20how%20it%20is%20set%20up%20if%20perhaps%20I%20may%20have%20made%20a%20mistake%20there.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEdit%3A%3C%2FP%3E%3CP%3EI%20also%20added%20a%20picture%20of%20the%20profile%20if%20that%20will%20help%20with%20the%20visualization%20of%20the%20problem.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20in%20advance%20for%20your%20help.%26nbsp%3B%20I%20am%20eager%20to%20learn%20about%20Access%20and%20finish%20this%20project%20with%20your%20guidance.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2410850%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAccess%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2410867%22%20slang%3D%22en-US%22%3ERe%3A%20Getting%20a%20field%20from%20another%20form%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2410867%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1069909%22%20target%3D%22_blank%22%3E%40ebenton%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hey Guys,

 

I have a survey attached to a user profile, and I am trying to connect it to a table with recommendations based on the user's input.  I am only just started learning about Access 3 weeks ago and am really struggling on this.  The recommendations are attached to a form which I would like the user to be able to open in their profile.  

 

To accomplish this, I am trying to pass the foreign key of the survey to the recommendations form to link the two.  I have attached some code of how I am trying to do this, but if anyone knows of a better alternative, I am all ears.  I have also attached the relationships table to give you an idea how it is set up if perhaps I may have made a mistake there.  

 

Edit:

I also added a picture of the profile if that will help with the visualization of the problem.  

 

Thank you in advance for your help.  I am eager to learn about Access and finish this project with your guidance.  

 

 

4 Replies
best response confirmed by ebenton (Occasional Contributor)
Solution

@ebenton 

 

Your code passes a SQL Select statement to the second form. You ONLY need to pass the appropriate fields for the person and for the recommendation. 

In addition, the second line is redundant. Your first line opens the recommendations form already filtered to that person.

 

You can pass both filtering values in a single line, something like this.


SurID = DLookup ("SurID", "Surveys", "Survey.PersonID_fk = " & Me.PersonID)
DoCmd.OpenForm "Recommendations",,, "PersonID_fk = " & Me.PersonID & " AND SurveyID_FK = " & SurID

@George Hepworth 

 

George,

 

This worked perfectly.  Thank you so much for taking the time to help me out.  

 

Cheers,

Ebenton

Congratulations on solving the problem.

Continued success with your project.