Solved Search Student ID Or Student Name

smtazulislam

Member
Local time
Today, 02:31
Joined
Mar 27, 2020
Messages
808
Hello, can anyone help me.
Student Edit Form :
I have two field Student ID = txtStudentID and Student Name = cboStudentName In Student Data Form.
I want to show in this form when I enter studentID then cboStudentName showed this student name even instant set form all data. Also if I cbostudentName to select student Name then showed student ID as well and also instant form data.
Note: StudentID : Primary KEY
 
how many column does cboStudentName has?
for this to work txtStudentID and cboStudentName must not be Bound.

1. Add code to txtStudentID After UpdateUpdate event :

private sub txtStudentID_AfterUpdate()
If Not IsNull(Me!txtStudentID) Then
Me!cboStudentName = DLookup("[Student Name]", "tblStudent", "[Student ID]=" & Me!txtStudentID) & ""
If Trim(Me!cboStudentName & "") <> "" Then
Me.RecordSource = "SELECT * FROM tblStudent WHERE [Student ID]=" & Me!txtStudentID
End If
End If
End Sub


2.Add code to cboStudentName_AfterUpdate event:
If Not IsNull(Me!cboStudentName) Then
Me!txtStudentID= DLookup("[Student ID]", "tblStudent", "[Student Name]='" & Me!cboStudentName & "'") & ""
If Trim(Me.txtStudentID & "") <> "" Then
Me.RecordSource = "SELECT * FROM tblStudent WHERE [Student ID]=" & Me!txtStudentID
End If
End If
End Sub
 
Thank you so much for reply.
Student field column 1 only.
When I enter the student ID form instant data in the form and student name showed in combo box (cbostudentName). But Combo box dont have drop list in others student name.
Please check I attached Student DB
I have 38+ students.
 

Attachments

Last edited:
here test this.
 

Attachments

here test this.
Great Job !, Thank you so much for help. I really appreciate for kinds of help. thanks again.
Can I get title correction please, If enter a number of StudentID in search box (txtStudentID) and this ID is not found in the RecordsetClone. Then want to give a message to user "Enter your Student ID is not found". And if found data , no need to messaged.

Thank you.
 

Users who are viewing this thread

Back
Top Bottom