Assistance needed in establishing table relationship

Voyager

Registered User.
Local time
Today, 18:47
Joined
Sep 7, 2017
Messages
95
Hi Experts,
I have three tables as user,task and worktime each with an autonumbered field as primary key.
User table has list of users,Task table has list of tasks to be performed by the users and worktime table will be having taskid , wrkid, start and end time of the task.
I have set the fields taskid and wrkid in worktime table as number fields and they will refer to the primarykey of their respective table.
I have done that since I dont want to save the taskname or username again in the worktime table as they are already listed in their respective tables.

I have established one to many relationship with task and worktime table with referential integrity. However I am unable to establish such relationship with referential
integrity with user table. Hence I created a code as follows

Code:
Private Sub Command2_Click()
Dim db As DAO.Database
Dim rt As Recordset
Set db = CurrentDb
Set rt = db.OpenRecordset("worktime", dbOpenDynaset)
rt.AddNew
rt("taskid") = DLookup("[tid]", "[task]", "[taskname]= '" & Me.Text0 & "'")
rt("usrid") = DLookup("[uid]", "[user]", "[uname]= '" & Me.Combo3 & "'")
rt("start") = Me.Text5
rt("End") = Me.Text7
rt.Update
rt.Close
Set rt = Nothing
Set db = Nothing
End Sub

Though it works I think I am not getting few things right like using dlookup. I have attached a test db for reference
Is there any better way? Could you assist?
 

Attachments

Users who are viewing this thread

Back
Top Bottom