I am trying to run a module from a button on a form where I populate a subform from Query1 with a product formula. The module is supposed to check whether the product formula can be implemented given enough raw material inventory. So, I'm trying to loop through my product formula based on OrderID and MaterialID(Mate rial Name) and check against the current stock inventory table. If any of the ingredients required for the product to be made is over the available stock inventory on hand, then I want an error to be displayed, otherwise I don't want any errors.
The problem I'm having is with the Compile Error at the line where it states:
I'd appreciate any help possible, THANKS!!
The entire code is as follows:
The problem I'm having is with the Compile Error at the line where it states:
Code:
Sub check_quantity ()
The entire code is as follows:
Code:
Option Compare Database
Option Explicit
Sub check_quantity()
On Error GoTo err_check_quantity
Dim material As Variant
Dim totalKg As Variant
queryString As String
queryString2 As String
Quantity As Variant
valid As Integer
strMsg As String
Dim Rs As DAO.Recordset
Dim Rs2 As DAO.Recordset
Dim Db As DAO.Database
Set Db = CurrentDb()
queryString = "SELECT * FROM Query1 WHERE [ProductName] = '" & [Forms]![Batchsheet Subform]![ProductName] & "' AND [OrderID] = " & [Forms]![Batchsheet Subform]![OrderID] & ";"
Set Rs = Db.OpenRecordset(queryString, dbOpenDynaset)
If Not (Rs.BOF And Rs.EOF) Then
Rs.MoveLast
Rs.MoveFirst
With Rs
Do While Not Rs.EOF
material = Rs.Fields("MaterialID").Value
totalKg = Rs.Fields("Total (kg)").Value
queryString2 = "SELECT * FROM RawMaterials WHERE [ItemName] = '" & material & ";"
Set Rs2 = Db.OpenRecordset(queryString2, dbOpenDynaset)
If Not (Rs2.BOF And Rs2.EOF) Then
Rs2.MoveLast
Rs2.MoveFirst
Quantity = Rs2.Fields("InStock").Value
If totalKg > Quantity Then
valid = 0
Else
valid = 1
End If
Select Case valid
Case 0
strMsg = " Order cannot currently be completed" & _
vbCrLf & " Please verify you have enough " & material & "inventory to complete this order."
MsgBox strMsg, vbInformation, "INVALID Raw Material Level"
Case 1
Rs.MoveNext
End Select
Loop
End With
Rs.Close
Rs2.Close
Db.Close
Set Rs = Nothing
Set Rs2 = Nothing
Set Db = Nothing
exit_check_quantity:
Exit Sub
err_check_quantity:
MsgBox Err.decsription
Resume exit_check_quantity
End Sub
Comment