By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,337 Members | 2,234 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,337 IT Pros & Developers. It's quick & easy.

Command buttons to add related records

P: 9
Hi,

I have seen very similar questions which have not really helped me, so thought I'd better ask for some more help.

I have a form called fsubAnimalDetails(which holds data on animals sampled, with the PK anmAnimalID)

What I am trying to do is put a command button on fsubAnimalDetails, which then opens another form frmAnimalSamples, and then details all the different samples taken from a specific animal in a specific village. The records on frmAnimalSamples is linked to the records in fsubAnimalDetails using anmAnimalID.

I want the button to open the form, and for it to only show records for the specific animal that is selected in fsubAnimalDetails. Also, if a new record is added in frmAnimalSamples, the anmAnimalID for that animal is automatically entered into the FK field in that form.

At the moment the form opens, and it is filtered for only records relating to that animal, but when a new record is entered the AnimalID is blank - how can I get this to show the AnimalID that was selected in the initial fsubAnimalDetails?

I set it up as it is using the wizard, as I have no knowledge of VBA, so if you could help with the code I'd really appreciate it!

Thanks,

Nicola
Mar 12 '07 #1
Share this Question
Share on Google+
3 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
Nicola

If the original form remains open then the FK will be equal to ...
Expand|Select|Wrap|Line Numbers
  1. Forms![MainFormName]![fsubAnimalDetails].Form![anmAnimalID]
  2.  
I am assuming fsubAnimalDetails is a subform because of it's name.

To set it you will need to trigger it with an event. In the AfterUpdate event of one of the control boxes that needs to be entered for each record (set to required) put the following ...
Expand|Select|Wrap|Line Numbers
  1. Me.anmAnimalID = 
  2. Forms![MainFormName]![fsubAnimalDetails].Form![anmAnimalID]
  3.  
Mary
Mar 12 '07 #2

P: 9
Thanks Mary, I have it working now!

Nicola

Nicola

If the original form remains open then the FK will be equal to ...
Expand|Select|Wrap|Line Numbers
  1. Forms![MainFormName]![fsubAnimalDetails].Form![anmAnimalID]
  2.  
I am assuming fsubAnimalDetails is a subform because of it's name.

To set it you will need to trigger it with an event. In the AfterUpdate event of one of the control boxes that needs to be entered for each record (set to required) put the following ...
Expand|Select|Wrap|Line Numbers
  1. Me.anmAnimalID = 
  2. Forms![MainFormName]![fsubAnimalDetails].Form![anmAnimalID]
  3.  
Mary
Mar 15 '07 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
Thanks Mary, I have it working now!

Nicola
Great.

Mary
Mar 15 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.