Private Sub frmCover_AfterUpdate()
Dim strBatType As String
Dim strsql As String
Dim objRS As Recordset
Dim strCW As String
Me.SN.SetFocus
If Me.SN.Text = "" Then
MsgBox ("Enter A Serial Number")
Exit Sub
End If
Me.CoverWeight.SetFocus
If Me.frmCover.Value = 1 Then
Me.CoverWeight.Value = 0
Else
strBatType = Left(Me.SN.Value, 1)
'NEED TO VALIDATE THE BATTERY TYPE VALUE ASSGINED ABOVE.
'TODO: THE VALIDATION SHOULD ALSO BE DONE WHEN THE SERIAL NUMBER IS FIRST ENTERED INTO THE FORM.
'QUERY THE TABLE FOR COVER WEIGHTS
strsql = "SELECT CoverWeight FROM CoverWeights WHERE BatteryType = '" & strBatType & "'"
Set objRS = CurrentDb.OpenRecordset(strsql) (This is where the problem is)
If Not objRS.EOF Then
'EXTRACT THE COVERWEIGHT
strCW = objRS.Fields("CoverWeight").Value
Me.CoverWeight.Value = strCW
Else
'RETURN MSG BOX INDICATING THE COVERWEIGHT WAS NOT FOUND.
MsgBox ("Cover Weight Does Not Exist")
Exit Sub
End If
End If
Me.NetWeight.SetFocus
Me.NetWeight.Value = Me.GrossWeight.Value - Me.CoverWeight.Value
Me.WeightLoss.SetFocus
Me.WeightLoss.Value = Me.PostWeight.Value - Me.NetWeight.Value
If Me.PostWeight.Value <> 0 Then
Me.PercentWeightLoss.SetFocus
Me.PercentWeightLoss.Value = Me.WeightLoss.Value / Me.PostWeight.Value
Else
Me.PercentWeightLoss.SetFocus
Me.PercentWeightLoss.Value = 0
End If
Me.Damage.SetFocus
End Sub
|