Auto entering the staff ID

A

Ant

I have a Staff table and emergency contact table with a one to many
relationship. I have then created a linked form so that I can view
emergency contact details of a staff member. When I click on the command
button on the staff form it jumps to the emergency contact details of that
staff member however if I try to enter a new emergency number for say staff
member 5, I can not do this because Access can not find a field on my child
form with matching details on my parent form. I do understand why this is
but I would like access to automatically enter the staff ID number without
relying on the user to do it, like it would if it was a sub-form within the
main form. I have spent ages trying to do this what I thought would be a
simple with no success can any one help?
 
J

John Vinson

I have a Staff table and emergency contact table with a one to many
relationship. I have then created a linked form so that I can view
emergency contact details of a staff member. When I click on the command
button on the staff form it jumps to the emergency contact details of that
staff member however if I try to enter a new emergency number for say staff
member 5, I can not do this because Access can not find a field on my child
form with matching details on my parent form. I do understand why this is
but I would like access to automatically enter the staff ID number without
relying on the user to do it, like it would if it was a sub-form within the
main form. I have spent ages trying to do this what I thought would be a
simple with no success can any one help?

One way is to pass the ID in the OpenArgs method of the OpenForm
event, and then use the second form's Open event to set the passed
value as the default. Air code:

DoCmd.OpenForm "frmEmergencies", <...>, OpenArgs := Me!txtStaffID

and then in frmEmergencies' open event;

Private Sub Form_Open(Cancel as Integer)
If Me.OpenArgs & "" <> "" Then
Me!txtStaffID.DefaultValue = "'" & Me.OpenArgs & "'"
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top