473,378 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Create a second record in a table for same FK

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
6 1430
missinglinq
3,532 Expert 2GB
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
32,556 Expert Mod 16PB
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
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
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
3,532 Expert 2GB
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
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

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

Similar topics

1
by: Jack | last post by:
I created a trigger in the "source table" that will "feed" and second table. The trigger is as follows: CREATE TRIGGER ON dbo.FromUPS FOR INSERT AS Declare @Count int Select @Count =...
7
by: Wolfgang Kreuzer | last post by:
Hello all, I have two tables - Projects and ProjectStruct Table Projects contains master records of the projects, ProjectStruct allows to define a project herarchie and contains the fields...
10
by: Mark | last post by:
I have a table about people containing 25 fields. The table contains the usual fields - first, last, address, city, state and zip. There is no primary key. These fields all have data with the...
1
by: Dave | last post by:
I have a form which is based on a table (a) with over 6000 records.I have a button on this form which will open another form with related data from another table (b). What I want to do is open the...
6
by: skgolden | last post by:
My husband and I own a small temporary labor company and deal with 4 major clients (A,B,C & D), each of which has about 2 dozen units in our tristate area that we deal with (ie, Company A, units...
24
by: flkeyman | last post by:
Work in legal office. Trying to create solid designed database structure. This is list of tables w/fields and primary keys. Any comments/advice greatly appreciated. tbl-Defendants CaseNumber...
5
by: Apple | last post by:
May anyone can teach me how to assign a autonumber, I want to create a number that is starting with year(auto change to year 2006) + autonumber (eg. 2005-0001, 2005-0002)
4
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query,...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.