Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 30th, 2003, 04:48 PM
Authorized User
 
Join Date: Sep 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Add Records to Table with 1 to Many Relationship

I am tracking employee's leave. The Table tblEmployeeLeave has the following fields:


SSN
LeaveType
LeaveAmount
LeaveDate

tblEmployeeLeave is related to the Table tblEmployees by SSN. It is a one to many Relationship (One employee may be off work numerous times)

I want my Form frmEmployeeLeave to read

SSN
LastName
FirstName

from the Table tblEmployees and I want to be able to enter

LeaveType
LeaveAmount
LeaveDate

for the employee, then save

SSN
LeaveType
LeaveAmount
LeaveDate

to tblEmployeeLeave as a new record.

Any help will be greatly appreciated.

Thanks,

David
 
Old September 30th, 2003, 05:42 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What exactly is your question? What do you have so far?

Peter
 
Old September 30th, 2003, 06:13 PM
Authorized User
 
Join Date: Sep 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by planoie
 What exactly is your question? What do you have so far?

Peter
 Hi Peter,

Thank you for getting back to me.

Here is what I want to do:

1. Open a form that allows me to select specific employees who have been off work.

2. Place the SSN, LastName and FirstName of the chosen employee into my form.

3. Input LeaveDate, LeaveType and LeaveAmount into the form.

4. Add new record by placing SSN, LeaveDate, LeaveType, and LeaveAmount into tblEmployeeLeave. (Presumable, the one to many relationship eliminates the need to also put employee's name into the tblEmployeeLeave, since tblEmployeeLeave is related to tblEmployee.)

This is what I have done:

1. Created relationship between tblEmployees and tblEmployeeLeave

2. Created form that has field for SSN, LastName, FirstName, LeaveDate, LeaveType and LeaveAmount.


I do not know how to place SSN, LastName and FirstName from tblEmployees into my form, so I can input leave information regarding specific employee.

I hope this clears it up.

Thanks,

David

 
Old October 1st, 2003, 03:27 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What are you using for your front end application.

Sal

 
Old October 1st, 2003, 04:01 PM
Authorized User
 
Join Date: Sep 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Sal,

I'm only using Access 2002 and the VBA application that comes with it.

Thanks,

David

 
Old October 2nd, 2003, 10:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Create a query (in SQL) that look like this:

Code:
SELECT e.SSN, e.LastName, e.FirstName, l.LeaveType, l.LeaveAmount, l.LeaveDate
FROM tblEmployees e INNER JOIN tblEmployeeLeave l ON e.SSN = l.SSN
WHERE e.SSN = [Please enter an employees SSN:];
Save this query and base your form on it. When you open the form an input box will be displayed asking you to enter an SSN, the form will then have all the data it needs to display that employees leave details.

Regards
Owain Williams
 
Old October 2nd, 2003, 10:12 AM
Registered User
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, I hope this can help. Since you already have a relationship you'll only get the SSN from the Form and map that SSN into the tblEmployess.

So everytime that you want to show the leave information on the user, you'll have to map using the SSN from the two tables, first match the SSN to get the Name, Addres, etc from the tblEmployees and secont, match the SSN to get the leave information of the employee from the tblEmployeeLeave. Did it solved your query?

 
Old October 2nd, 2003, 10:19 AM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just set up a form in "Single Form View" (Employees Form) and use the employees table as a data source.
Then create a form in "Data Sheet View" (Employees LeaveForm) use the employees leave table as a data source, and use it as a subform inside your "Employees Form"
Then use the SSN as Link Child Fields. This will ensure that your data is being entered in the correct tables.


Sal
 
Old October 5th, 2003, 05:35 AM
Authorized User
 
Join Date: Sep 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Sal,

It worked like a charm.

David

p.s. I appreciate everyone's help on this one.


Quote:
quote:Originally posted by sal
 Just set up a form in "Single Form View" (Employees Form) and use the employees table as a data source.
Then create a form in "Data Sheet View" (Employees LeaveForm) use the employees leave table as a data source, and use it as a subform inside your "Employees Form"
Then use the SSN as Link Child Fields. This will ensure that your data is being entered in the correct tables.


Sal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding many to many relationship table osemollie Pro VB Databases 7 July 28th, 2006 03:52 AM
need to copy and add new records in table chacquard Access VBA 12 May 2nd, 2005 09:58 AM
Copying Table Relationship Diagram mike123abc SQL Server 2000 1 February 19th, 2004 09:16 AM
How to add records hdvan SQL Server ASP 2 September 24th, 2003 12:43 AM
Update or add multiple table records rosenzl VB.NET 3 June 12th, 2003 01:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.