input a field from a table and get all information from another table (1 Viewer)

Unixaix

New member
Local time
Yesterday, 16:58
Joined
Apr 7, 2019
Messages
6
How to get tblStudent table record data by input studentCode
There are two tables:

tblStudent:
StudentID autonumber
StudentCode Number ; lookup from StudentCode Table
StudentName short Text
StudentAddress short Text

tblStudentCode:
CodeID autonumber
StudentCode short text

Now I want to design a query or form:
get the studentCode from tblStudent, and display studentCode,StudentName, StudentAddress

Please help, I am a new programmer.
Thanks!
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:58
Joined
Oct 29, 2018
Messages
21,447
Hi. Will this work?
Code:
SELECT * FROM tblStudent WHERE StudentCode=[Enter Student Code]
 

Unixaix

New member
Local time
Yesterday, 16:58
Joined
Apr 7, 2019
Messages
6
Hi. Will this work?
Code:
SELECT * FROM tblStudent WHERE StudentCode=[Enter Student Code]
What I want to do is:
use lookup display studentCode, then I select a StudentCode,
and get the match student information and display in the screen.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:58
Joined
Feb 19, 2002
Messages
43,206
The problems with lookup fields in a table are many. You are about to run into one of them. Even though tblStudent.StudentCode "looks" lit it is text, if it is a Lookup, it is actually CodeID.

1. Remove the lookup from tblStudent
2. Rename the column from StudentCode to CodeID so that you actually know what data is contained
3. Use a query to join the two tables.
Select tblStudent.*, tblStudentCode.StudentCode
From tblStudent Inner Join tblStudentCode on tblStudent.CodeID = tblStudentCode.CodeID

Since you are new, it is best to always use the QBE to create queries.
1. Open the Query Designer
2. Choose tblStudent and then tblStudentCode from the table list and close the dialog.
3. Select the columns you want from each table. Double-click on a column name to do it one at a time (there are other methods to select all).
4. Draw a join line between the two tables connecting on the CodeID field. Using click and drag. A dialog will open. Make sure you have selected the correct two fields. Change the selected values if necessary. Normally you will use an inner join which is the first option. Also, if you have created relationships in the Relationships window, Access will automatically draw the join lines because you have already told it how the tables are related.
5. Save the query using a meaningful (but not overly long name)
 

Unixaix

New member
Local time
Yesterday, 16:58
Joined
Apr 7, 2019
Messages
6
Hi. Will this work?
Code:
SELECT * FROM tblStudent WHERE StudentCode=[Enter Student Code]
What I want to do is:
use lookup display studentCode, then I select a StudentCode,
and get the match student information and display in the screen.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:58
Joined
Oct 29, 2018
Messages
21,447
What I want to do is:
use lookup display studentCode, then I select a StudentCode,
and get the match student information and display in the screen.
Hi. There's a lot of ways to do this. I am not sure what you have in mind. You could take a look at some demos and see if there's one you could use or post a mockup image, so we can help guide you on how to build it.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:58
Joined
Feb 19, 2002
Messages
43,206
On the bound student form, add an unbound combo in your form's header section to separate it from the bound fields. The RowSource will be tblStudentCode. Make the colum widths 0", 1". This will hide the CodeID and show the studentCode value.

Change the Recordsource for the student form to a query. The query will reference the unbound combo in its where clause:

Select ..
From ..
Where CodeID = Forms!frmStudent!cboLookupStudent

Then in the AfterUpdate event of the combo, add a requery:

Me.Requery

The form will always open blank since when it opens there is no value in the combo. Once a value is added to the combo, the desired record is pulled up.
 

Users who are viewing this thread

Top Bottom