OnClick Event Procedure not working.

mailman26

New member
Local time
Today, 11:05
Joined
Mar 13, 2012
Messages
8
Private Sub Command14_Click()
'Variable Declaration
Dim RawMaterial As Integer
Dim YieldCalc As Integer
Dim cts As DAO.Database
Dim rs As DAO.Recordset
Dim qry As String
Dim tPCon, tPCat As String

Set cts = CurrentDb

'Initialising the variable by setting it to 0
YieldCalc = 0

'Set focus on the control then take the text from that control and store it in a variable.
ProductCondition.SetFocus
tPCon = ProductCondition.Text

'Set focus on the control then take the text from that control and store it in a variable.
ProductCategory.SetFocus
tPCat = ProductCategory.Text


'Testing to see if the record being entered is the Raw Material
'If it is then the Yield will be equal to 1 i.e 100%
If tPCon = "Raw" And tPCat = "Material" Then
YieldCalc = 1
'Inserting the Yield in the Yield field in the form
Product_Weight_perc.SetFocus
Product_Weight_perc.Text = YieldCalc

'If the record is one of the other categories then it will perform the following
Else

'Retrieves the rawMaterial amount in the Stageing table that is associated with the values being currently entered
'And storing it in the variable RawMaterial
ProductionDate.SetFocus
qry = "Select Product_Weight_lbs From tbl_Stageing Where Production_Date = " & ProductionDate.Text

TrailerID.SetFocus
qry = qry & " and trailer_id = '" & TrailerID.Text & "'"


EmployeeID.SetFocus
qry = qry & " and Employee_ID = " & EmployeeID.Text


StageID.SetFocus
qry = qry & " and Stage_ID = '" & StageID.Text & "'"

qry = qry & " and Product_Condition = 'Raw' and Product_Category = 'Material'"

Set rs = cts.OpenRecordset(qry, dbOpenDynaset)
Do While Not rs.EOF
RawMaterial = rs!Product_Weight_lbs


rs.MoveNext
Loop

rs.Close

If RawMaterial > 0 Then
'Calculates the yield for that particular record in relation to the associated Raw Material retrieve from the staging table.
YieldCalc = (ProductWeightlbs / RawMaterial) * 100

'Inserting the Yield in the Yield field in the form
Product_Weight_perc.SetFocus
Product_Weight_perc.Text = YieldCalc

Else
MsgBox ("Please enter the Raw Material first")
End If

End If
If Me.Dirty Then Me.Dirty = False
End Sub











I created a form to keep track of production yield for a textile company. I created this event procedure to be executed when the "save record" button is clicked. It should calculate the "yield (%) per stage" and enter the record. It worked fine when I tested it, about a month ago. Now that Ive gone back to the database and started using it, the save record button doesn't work ( it doesn't make the calculation) and doesn't save the record.

Why?



Thanks for the help in advance.


Mailman
 

Users who are viewing this thread

Back
Top Bottom