C
cobainc0
I have two forms (linked)
The main form contains employee details(1)in a listbox.
The user clicks on an employee in the list box, then selects the toggle
button to the linked form...a booking form(2)where the employee primary key
is present. I want to keep the primary key but i want the rest of the booking
form fields to be blank and a button that adds the new booking booking record
to/for that employee.
EMPLOYEE FORM CODE (PARENT)
Option Compare Database
Sub Form_Current()
On Error GoTo Form_Current_Err
If ChildFormIsOpen() Then FilterChildForm
Form_Current_Exit:
Exit Sub
Form_Current_Err:
MsgBox Error$
Resume Form_Current_Exit
End Sub
Sub ToggleLink_Click()
On Error GoTo ToggleLink_Click_Err
If ChildFormIsOpen() Then
CloseChildForm
Else
OpenChildForm
FilterChildForm
End If
ToggleLink_Click_Exit:
Exit Sub
ToggleLink_Click_Err:
MsgBox Error$
Resume ToggleLink_Click_Exit
End Sub
Private Sub FilterChildForm()
If Me.NewRecord Then
Forms![tblbooking].DataEntry = True
Else
Forms![tblbooking].Filter = "[Tutor ID] = " & Me.[Employee ID]
Forms![tblbooking].FilterOn = True
End If
End Sub
Private Sub OpenChildForm()
DoCmd.OpenForm "tblbooking"
If Not Me.[ToggleLink] Then Me![ToggleLink] = True
End Sub
Private Sub CloseChildForm()
DoCmd.Close acForm, "tblbooking"
If Me![ToggleLink] Then Me![ToggleLink] = False
End Sub
Private Function ChildFormIsOpen()
ChildFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, "tblbooking")
And acObjStateOpen) <> False
End Function
Private Sub List24_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Employee ID] = " & Str(Nz(Me![List24], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
BOOKING FORM CODE (CHILD)
Option Compare Database
Private Sub Form_AfterUpdate()
DoCmd.GoToRecord , , acNewRec
End Sub
Sub Form_Load()
On Error GoTo Form_Load_Err
If ParentFormIsOpen() Then Forms![tblemployee]!ToggleLink = True
Form_Load_Exit:
Exit Sub
Form_Load_Err:
MsgBox Error$
Resume Form_Load_Exit
DoCmd.GoToRecord , , acNewRec
End Sub
Sub Form_Unload(Cancel As Integer)
On Error GoTo Form_Unload_Err
If ParentFormIsOpen() Then Forms![tblemployee]!ToggleLink = False
Form_Unload_Exit:
Exit Sub
Form_Unload_Err:
MsgBox Error$
Resume Form_Unload_Exit
End Sub
Private Function ParentFormIsOpen()
ParentFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, "tblemployee")
And acObjStateOpen) <> False
End Function
Please help i can see why its bringing all records pertainning to an employee
but i just want to add new booking records to each employee. As it it now i
could only edit the records in booking form. Is there another way, changing
the code? or creating a query? any suggestions welcome. Thanks in advance
The main form contains employee details(1)in a listbox.
The user clicks on an employee in the list box, then selects the toggle
button to the linked form...a booking form(2)where the employee primary key
is present. I want to keep the primary key but i want the rest of the booking
form fields to be blank and a button that adds the new booking booking record
to/for that employee.
EMPLOYEE FORM CODE (PARENT)
Option Compare Database
Sub Form_Current()
On Error GoTo Form_Current_Err
If ChildFormIsOpen() Then FilterChildForm
Form_Current_Exit:
Exit Sub
Form_Current_Err:
MsgBox Error$
Resume Form_Current_Exit
End Sub
Sub ToggleLink_Click()
On Error GoTo ToggleLink_Click_Err
If ChildFormIsOpen() Then
CloseChildForm
Else
OpenChildForm
FilterChildForm
End If
ToggleLink_Click_Exit:
Exit Sub
ToggleLink_Click_Err:
MsgBox Error$
Resume ToggleLink_Click_Exit
End Sub
Private Sub FilterChildForm()
If Me.NewRecord Then
Forms![tblbooking].DataEntry = True
Else
Forms![tblbooking].Filter = "[Tutor ID] = " & Me.[Employee ID]
Forms![tblbooking].FilterOn = True
End If
End Sub
Private Sub OpenChildForm()
DoCmd.OpenForm "tblbooking"
If Not Me.[ToggleLink] Then Me![ToggleLink] = True
End Sub
Private Sub CloseChildForm()
DoCmd.Close acForm, "tblbooking"
If Me![ToggleLink] Then Me![ToggleLink] = False
End Sub
Private Function ChildFormIsOpen()
ChildFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, "tblbooking")
And acObjStateOpen) <> False
End Function
Private Sub List24_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Employee ID] = " & Str(Nz(Me![List24], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
BOOKING FORM CODE (CHILD)
Option Compare Database
Private Sub Form_AfterUpdate()
DoCmd.GoToRecord , , acNewRec
End Sub
Sub Form_Load()
On Error GoTo Form_Load_Err
If ParentFormIsOpen() Then Forms![tblemployee]!ToggleLink = True
Form_Load_Exit:
Exit Sub
Form_Load_Err:
MsgBox Error$
Resume Form_Load_Exit
DoCmd.GoToRecord , , acNewRec
End Sub
Sub Form_Unload(Cancel As Integer)
On Error GoTo Form_Unload_Err
If ParentFormIsOpen() Then Forms![tblemployee]!ToggleLink = False
Form_Unload_Exit:
Exit Sub
Form_Unload_Err:
MsgBox Error$
Resume Form_Unload_Exit
End Sub
Private Function ParentFormIsOpen()
ParentFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, "tblemployee")
And acObjStateOpen) <> False
End Function
Please help i can see why its bringing all records pertainning to an employee
but i just want to add new booking records to each employee. As it it now i
could only edit the records in booking form. Is there another way, changing
the code? or creating a query? any suggestions welcome. Thanks in advance