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

Create a second record in a table for same FK

P: 16
I'll try and explain!

first table is tDemographics
second table is tassessment

each person can have two or more assessments, so I have a one two many relationship with PersonID as PK.

On my summary form I can hit a command button to go to form "fassessment".
I want another command key (would be called something like 'new assessment for this person') to open fAssessment with a new record but with the person ID already attributed.

hope this makes sense!
hope someone can help!

many thanks
Apr 21 '08 #1
Share this Question
Share on Google+
6 Replies


missinglinq
Expert 2.5K+
P: 3,532
Pass the ID as the OpenArgs when opening the second form. In your calling form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub NewAssessment_Click()
  2.   DoCmd.OpenForm "fAssessment", , , , , , Me.PersonID    
  3. End Sub
  4.  
Then, in fAssessment:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.   If Len(Nz(Me.OpenArgs, "")) > 0 Then
  3.      'Move to a new record
  4.     DoCmd.GoToRecord , , acNewRec
  5.     'Plug the ID into the new record
  6.     Me.PersonID = Me.OpenArgs
  7.   End If
  8. End Sub
Welcome to bytes!

Linq ;0)>
Apr 21 '08 #2

NeoPa
Expert Mod 15k+
P: 31,489
I think this is typically done with sub-forms.

Let me know if you're interested in going further and need more help.
Apr 22 '08 #3

P: 16
Great - easy when you know how!!!
feel free to look out for might next newbie posting!!!


Pass the ID as the OpenArgs when opening the second form. In your calling form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub NewAssessment_Click()
  2.   DoCmd.OpenForm "fAssessment", , , , , , Me.PersonID    
  3. End Sub
  4.  
Then, in fAssessment:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.   If Len(Nz(Me.OpenArgs, "")) > 0 Then
  3.      'Move to a new record
  4.     DoCmd.GoToRecord , , acNewRec
  5.     'Plug the ID into the new record
  6.     Me.PersonID = Me.OpenArgs
  7.   End If
  8. End Sub
Welcome to bytes!

Linq ;0)>
Apr 23 '08 #4

P: 16
Hi Linq

thanks for that code, one other thing.

the form opens and the record is created, If for example I open this form by mistake how do I use a cmd button (ie cmdCancel) to close the form and cancel the record, if I close the the form the record remains.

hope you can help

Pass the ID as the OpenArgs when opening the second form. In your calling form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub NewAssessment_Click()
  2.   DoCmd.OpenForm "fAssessment", , , , , , Me.PersonID    
  3. End Sub
  4.  
Then, in fAssessment:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.   If Len(Nz(Me.OpenArgs, "")) > 0 Then
  3.      'Move to a new record
  4.     DoCmd.GoToRecord , , acNewRec
  5.     'Plug the ID into the new record
  6.     Me.PersonID = Me.OpenArgs
  7.   End If
  8. End Sub
Welcome to bytes!

Linq ;0)>
Apr 28 '08 #5

missinglinq
Expert 2.5K+
P: 3,532
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCancel_Click()
  2.  Me.Undo
  3.  DoCmd.Close
  4. End Sub
Linq ;0)>
Apr 29 '08 #6

P: 16
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCancel_Click()
  2.  Me.Undo
  3.  DoCmd.Close
  4. End Sub
Linq ;0)>

Many Thanks it works great
barry
May 8 '08 #7

Post your reply

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