Ok, I’ve got a database whose function is primarily to track the number of labor hours assigned to each job order number (JON). I’m using Access2003.
I have two main tables: tblLaborHoursByJON and tblJobDescriptionsAddlInfo.
- tblLaborHoursByJON includes columns: JON, FiscalYear, DivisionCode, LaborHoursST, LaborHoursOT, and EstHours
· the combination of JON, FiscalYear, and DivisionCode is set as my primary key as there are multiple entries for each JON
o within each JON there are sometimes multiple entries by year or division
· this table specifically holds labor hour data
- tblJobDescriptionsAddlInfo includes columns: JON, Description, Award, Accept, Assist, and Parent
· the JON is the primary key here
· this table tracks descriptive info for each JON (it’s name, when it went into effect, if it’s related to another JON, etc.)
- the tables are related by JON
I want to create an input form to enter new information. For tblLaborHoursbyJON, I want the form to replace the old data if the JON/FiscalYear/DivisionCode primary key exists already. If not, I want it to create a new record. However, I need the form to check if descriptive data exists already for the JON being entered. If not, a separate form needs to open up to allow the user to enter information for those fields.
My problem is that I don’t know how to write VBA code. I created the form with input fields: JON, FiscalYear, DivisionCode, LaborHoursST, LaborHoursOT, and EstHours. At the bottom, I put a button [cmdEnter]. I set the properties of the button that OnClick [Event Procedure], but now I have to write the procedure.
I want the procedure to look like this:
Does JON exist?
If no,
Open frmAdditionalInfo
[user will enter the appropriate info: JON (from
previous form), JobDescription, Award, Accept,
Assist, ParentJON ]
On Click – cmdEnter
Append new record to tblJobDecription…
Close form
Continue to “If yes” of previous form (or restart
procedure)
If yes,
Does primary key exist?
If yes,
Replace record with new data
If no,
Create new record with this data
Close form
I’m just not sure how to turn this into code and would greatly appreciate help. I’m also open to suggestions if there’s a better way to do this.