Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 30th, 2003, 04:48 PM
Authorized User
 
Join Date: Sep 2003
Location: Upper Marlboro, Maryland, USA.
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
Reply With Quote
  #2 (permalink)  
Old September 30th, 2003, 05:42 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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

Peter
Reply With Quote
  #3 (permalink)  
Old September 30th, 2003, 06:13 PM
Authorized User
 
Join Date: Sep 2003
Location: Upper Marlboro, Maryland, USA.
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

Reply With Quote
  #4 (permalink)  
Old October 1st, 2003, 03:27 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Location: Clarksville, TN, USA.
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What are you using for your front end application.

Sal

Reply With Quote
  #5 (permalink)  
Old October 1st, 2003, 04:01 PM
Authorized User
 
Join Date: Sep 2003
Location: Upper Marlboro, Maryland, USA.
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

Reply With Quote
  #6 (permalink)  
Old October 2nd, 2003, 10:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Cardiff, , United Kingdom.
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
Reply With Quote
  #7 (permalink)  
Old October 2nd, 2003, 10:12 AM
Registered User
 
Join Date: Sep 2003
Location: , , .
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?

Reply With Quote
  #8 (permalink)  
Old October 2nd, 2003, 10:19 AM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Location: Clarksville, TN, USA.
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
Reply With Quote
  #9 (permalink)  
Old October 5th, 2003, 05:35 AM
Authorized User
 
Join Date: Sep 2003
Location: Upper Marlboro, Maryland, USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:21 AM.


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