Afi83 0 Light Poster

Hi there
I have a problem with coding application with relational database in access.
I have 3 table with relation to each other with one key. The tables are Faculty, Department and class. I relate each faculty to many departments and using the faculty id as foreign key in department table. For department table I do like the mentioned procedure.
Know I want to write a VB6 application that can read and write to these tables.

In my VB6 application I want to read and write to each table and showing them in datagrid.
For two table I don't have problem. But in three table I can't change the department table id so that I can write classes for different departments.
Here is what I have done till know:
Hope to describe the situation as it is. If something is unclear let me know for further explanation.
If there is something simpler for doing this let me know.
Thank you for your guides

Private Sub DataFaculty_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Dim ID As Integer
With FacultyRec    'The recordset for reading from faculty table
    ID = !Facid
End With
Call RelChange("faculty", "facultyid", ID, DataDepartment)  'subroutin for understanding the ID of relation to set the data grid to new values
End Sub

Private Sub RelChange(RelTable As String, relfield As String, ByVal match As Integer, Grid As DataGrid)
Dim RelRec As ADODB.Recordset
Dim SqlRel As String
Dim str As String
Set RelRec = New ADODB.Recordset
Sqlrec = "select * from " & RelTable & " Where " & relfield & "=" & match
RelRec.Open Sqlrec, Mcon, adOpenStatic, adLockOptimistic
Set Grid.DataSource = RelRec.DataSource
Grid.ReBind
End Sub

''But for three datagrid I have a problem:

Private Sub DataFaculty1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Dim ID As Integer
With DepartmentRec
    ID = !Facid                 
End With
Call RelChange("Department", "Facid", ID, DataDepartment)
End Sub
Private Sub DataDepartment_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Dim ID As Integer
With DepartmentRec
    ID = !Depid     '' Here is where the problem merges ID only remain the first ID in the department table and did not change when I click on the data grid

End With
Call RelChange("Class", "Departmentid", ID, DataClass)
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.