Hi there, I am in the process of creating multiple databases but have little experience with Access and my visual basic coding knowledge is limited and rusty. I have searched through some forum topics looking for help for my problems but seem to be missing it. Anyways, I will start with the first project...
I am trying to set up a simple database to calculate multiple costs. Essentially what I have is:
-1 table (tblTruckvalues)...with the fields: ID (autonumber), Job (text value), JobHour (number), JobCost(number) Year (Limited sized text value), Month (text), and Week (number)
-a corrseponding form (FrmTruckInput) which has text boxes for the fields of Year, JobHour, List boxes for Month (Jan- Dec), Week (1-5) and Job.
For simplicities sake, Job has 3 current values.. Truck1plow, Truck1sand, Truck2plow.
It also has a button (cmdSaveCalc) which currently saves the record upon clicking
What I am trying to do is associate integer values with each of the "jobs" so that I can calculate a total cost based on the user entered JobHour value.
For example
Truck1plow is $22, Truck1sand is $15, Truck2plow is $25.
I figure this involves an "if" statement in VB, so here is what I have attempted
Option Compare Database
Private Sub cmdSaveCalc_Click()
Dim Job1 As Currency
Dim Cost As Currency
Job1 = 15.5
Cost = 0
If Forms!frmTruckInput!Job.Value = Truck1Plow Then
Job1 = 22
ElseIf Forms!frmTruckInput!Job.Value = Truck1Sand Then
Job1 = 15
ElseIf Forms!frmTruckInput!Job.Value = Truck2Plow Then
Job1 = 25
End If
Cost = [JobHours] * Job1
'Tables!tblTruckvalues!JobCost.Value = Cost
DoCmd.RunSQL "INSERT INTO tblTruckvalues (JobCost) VALUES (Cost)"
On Error GoTo Err_cmdSaveCalc_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_cmdSaveCalc_Click:
Exit Sub
Err_cmdSaveCalc_Click:
MsgBox Err.Description
Resume Exit_cmdSaveCalc_Click
End Sub
I am aware that my currently active line lets me input the cost total (but in to the next possible record, but what I would like to do is be able to have the form automatically calculate the cost and input it in the current record on the table when the button is clicked. I was wondering if I am on a better track with the inactive line above (see red).
Any help, advice, or links would be greatly appreciated.
-ConfusedA
I am trying to set up a simple database to calculate multiple costs. Essentially what I have is:
-1 table (tblTruckvalues)...with the fields: ID (autonumber), Job (text value), JobHour (number), JobCost(number) Year (Limited sized text value), Month (text), and Week (number)
-a corrseponding form (FrmTruckInput) which has text boxes for the fields of Year, JobHour, List boxes for Month (Jan- Dec), Week (1-5) and Job.
For simplicities sake, Job has 3 current values.. Truck1plow, Truck1sand, Truck2plow.
It also has a button (cmdSaveCalc) which currently saves the record upon clicking
What I am trying to do is associate integer values with each of the "jobs" so that I can calculate a total cost based on the user entered JobHour value.
For example
Truck1plow is $22, Truck1sand is $15, Truck2plow is $25.
I figure this involves an "if" statement in VB, so here is what I have attempted
Option Compare Database
Private Sub cmdSaveCalc_Click()
Dim Job1 As Currency
Dim Cost As Currency
Job1 = 15.5
Cost = 0
If Forms!frmTruckInput!Job.Value = Truck1Plow Then
Job1 = 22
ElseIf Forms!frmTruckInput!Job.Value = Truck1Sand Then
Job1 = 15
ElseIf Forms!frmTruckInput!Job.Value = Truck2Plow Then
Job1 = 25
End If
Cost = [JobHours] * Job1
'Tables!tblTruckvalues!JobCost.Value = Cost
DoCmd.RunSQL "INSERT INTO tblTruckvalues (JobCost) VALUES (Cost)"
On Error GoTo Err_cmdSaveCalc_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_cmdSaveCalc_Click:
Exit Sub
Err_cmdSaveCalc_Click:
MsgBox Err.Description
Resume Exit_cmdSaveCalc_Click
End Sub
I am aware that my currently active line lets me input the cost total (but in to the next possible record, but what I would like to do is be able to have the form automatically calculate the cost and input it in the current record on the table when the button is clicked. I was wondering if I am on a better track with the inactive line above (see red).
Any help, advice, or links would be greatly appreciated.
-ConfusedA