Hello. Access 2007.
I have a staff form with a button that opens a second form to show their holiday details. But if I start a new holiday record it doesn't remember
their staff id number.
What's the best way to carry across the staff id to the holidays form please? Andy.
Create new record on secondary form
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
Create new record on secondary form
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
-
- 3StarLounger
- Posts: 287
- Joined: 09 Mar 2010, 23:16
- Location: Canberra Australia
Re: Create new record on secondary form
Set the default value of the StaffID control on the second form (it can be hidden) to:
=Forms("frmstaffDetails")!StaffID
This assumes that you left the staff form open when you open the second form.
=Forms("frmstaffDetails")!StaffID
This assumes that you left the staff form open when you open the second form.
Regards
John
John
-
- Administrator
- Posts: 78488
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Create new record on secondary form
You can use the On Load event of the holidays form to set the default value of StaffID:
where frmStaff is the name of the staff form and StaffID the id field.
Code: Select all
Private Sub Form_Load()
On Error Resume Next
Me.StaffID.DefaultValue = Chr(34) & Forms!frmStaff!StaffID & Chr(34)
End Sub
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
Re: Create new record on secondary form
Hello. Thanks both. Is there an advantage to using the On Load event? Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
-
- Administrator
- Posts: 78488
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Create new record on secondary form
If you only open the holidays form from the staff form, John's method is easier because it doesn't use VBA. But if the user can open the holidays form while the staff form is not open, you'd get #Error in staff id in a new record.
You won't get the error with the On Load event because the line On Error Resume Next prevents it.
You won't get the error with the On Load event because the line On Error Resume Next prevents it.
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 287
- Joined: 09 Mar 2010, 23:16
- Location: Canberra Australia
Re: Create new record on secondary form
If you always view Holidays in the context of having the Staff form open, the easiest solution of the lot would be to add Holidays as a subform to the Staff form, then Master and child linking will fill in StaffID automatically. You could add a Tab control, and put the Holidays on another page.
Regards
John
John