I use the following VBA to look up maximum, minimums and current quantities for a number of different parts. I havn't used VBA in a while and I can't remember how to do this in a single sub routine. I know there is a way to pass the value of the field part to the routine, but I can't find it here. In other words, I need to replace the name in the part field for whatever the name or number is.
Private Sub Part_BeforeUpdate(Cancel As Integer)
Dim rst As DAO.Recordset
Dim Low, High As Currency
Set rst = CurrentDb.OpenRecordset("Select St_Sym, Current_Qua,Lowest,Highest from Stock_Data where St_Sym = _'Part'")
If Me![Part] < Forms!Stock_Data![Lowest] Then
Low = Me![Part]
With rst
.Edit
!Lowest = Low
.Update
End With
rst.Close
Forms!Stock_Data![Lowest] = Me![Part]
End If
If Me![Part] > Forms!Stock_Data![Highest] Then
High = Me![Part]
With rst
.Edit
!Highest = High
.Update
End With
'Forms!Stock_Data![Highest] = Me![Part]
End If
With rst
Qua = !Current_Qua
End With
Me!Qua1 = Qua
End Sub
Thanks, I hope this makes sense. Bill
Private Sub Part_BeforeUpdate(Cancel As Integer)
Dim rst As DAO.Recordset
Dim Low, High As Currency
Set rst = CurrentDb.OpenRecordset("Select St_Sym, Current_Qua,Lowest,Highest from Stock_Data where St_Sym = _'Part'")
If Me![Part] < Forms!Stock_Data![Lowest] Then
Low = Me![Part]
With rst
.Edit
!Lowest = Low
.Update
End With
rst.Close
Forms!Stock_Data![Lowest] = Me![Part]
End If
If Me![Part] > Forms!Stock_Data![Highest] Then
High = Me![Part]
With rst
.Edit
!Highest = High
.Update
End With
'Forms!Stock_Data![Highest] = Me![Part]
End If
With rst
Qua = !Current_Qua
End With
Me!Qua1 = Qua
End Sub
Thanks, I hope this makes sense. Bill