Google Answers Logo
View Question
 
Q: Code for creating new fields in MS Access Database ( No Answer,   2 Comments )
Question  
Subject: Code for creating new fields in MS Access Database
Category: Computers > Programming
Asked by: accessnovice-ga
List Price: $5.00
Posted: 01 Aug 2005 12:26 PDT
Expires: 31 Aug 2005 12:26 PDT
Question ID: 550499
I need some easy way to have a form auto-populate a table with certain
fields. I'm using a table (for a company's payroll) that records daily
hours for employees. The table has, say, four relevant columns:
EmployeeName, DepartmentCode, Day, HoursWorked
The simplest way I've found of entering the data is to have a form
that, using a filter, picks out all entries where EmployeeName,
DepartmentCode match a chosen set, and where Day is within a range
that is present (one pay period).
Anyway, that part works fine, the problem is that I need some way to
create the 15 or so entries with 0 in the HoursWorked column, so that
my form has something to find.
What I'm looking for, then, is some way to create a macro or script
that will be invoked when opening the form in question. The form is
launched from another form that lets the user choose the data that it
will be filtering by, so it's not hard to get the data input, I just
need the code.
In English, this is what it would need to do:
Create entry in table DailyHours
	Set EmployeeName (using the field in the previous form)
	Set DepartmentCode (using the field in the previous form)
	Set Day = FirstDay (this day is taken from a field that is set once
the pay period is chosen)
	Set Hours = 0
Loop, but
	Set Day = FirstDay+1
Do until Day = (FirstDay of (PayPeriod+1)) -1

Clarification of Question by accessnovice-ga on 01 Aug 2005 12:41 PDT
If there is another way to achieve the desired result without a script
similar to the one I describe, that would be just as appreciated. I'm
not stuck on any one way of doing this. I can get pretty close to what
I want using subforms, for example (one for each day of the pay
period) but this method has certain problems (you can't tab across
subforms, it's messy and annoying to change, since you have to keep 15
almost identical forms...)
I'm sure there are simple ways of solving this seemingly simple problem.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Code for creating new fields in MS Access Database
From: willcodeforfood-ga on 01 Aug 2005 13:05 PDT
 
You can attach VBA code or a macro to the form's On Open or On Load
events.  To do this, open the form in design mode, click on the square
in the upper left hand corner of the design window, and then open the
properties window.  Choose the All or Event tab and scroll down to the
On Open or On Load events.  Click on the ellipses button on the right
side of the line to choose an event handler.

As far as having the form work from a set of template records as you
described, I'd create an Access table that is separate from the main
table that holds employee hours.  Call it tblEmployeeHoursTemplate for
example.  During the form's On Open, call a macro or write some code
to empty the tblEmployeeHoursTemplate table of records and populate a
fresh set of records with the initial parameters and values you need. 
If the user has already saved hours for this time period, populate the
tblEmployeeHoursTemplate table with the data that the user previously
saved.  In the bottom of the form put a Save button.  When the user
presses the save button, you'll want to delete any current records
from tblEmployeeHours (the main table) and then copy the records from
tblEmployeeHoursTemplate to tblEmployeeHours.  If you have multiple
users sharing the same Access database, you'll need to add an
additional field to the tblEmployeeHoursTemplate table so you can tell
which records belong to which user in which session.
Subject: Re: Code for creating new fields in MS Access Database
From: accessnovice-ga on 04 Aug 2005 12:52 PDT
 
Ok, then perhaps more precisely, I need a way to create these
dummy/empty entries with just the date for each day in succession. I
don't know macros or what code I could use to create these entries.
this might be really obvious, I don't know.
Thanks for your help, willcode.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy