I've revamped my code, and while it works, it does ask me twice the same
question. Can someone please help me out?
Thank you!
Public Sub Command0_Click()
Static Pickbox As String
Dim eUsed As Integer
Dim dUsed As Integer
Dim cUsed As Integer
Dim bUsed As Integer
Dim aUsed As Integer
Dim eRem As Integer
Dim dRem As Integer
Dim cRem As Integer
Dim bRem As Integer
Dim aRem As Integer
Dim ecurrent As Integer
Dim dcurrent As Integer
Dim ccurrent As Integer
Dim bcurrent As Integer
Dim acurrent As Integer
Dim aSQL As String
Dim bSQL As String
Dim cSQL As String
Dim dSQL As String
Dim eSQL As String
Dim tempsql As String
Pickbox = PBox()
DoCmd.OpenQuery "qryMakeTempPickbox", acViewNormal
DoCmd.Rename "tbltemp" & Pickbox, acTable, "tblTempPickbox"
eUsed = eUse(Pickbox)
dUsed = dUse(Pickbox)
cUsed = cUse(Pickbox)
bUsed = bUse(Pickbox)
aUsed = aUse(Pickbox)
ecurrent = DMax("[ESlots]", "tbltemp" & Pickbox, "")
dcurrent = DMax("[DSlots]", "tbltemp" & Pickbox, "")
ccurrent = DMax("[CSlots]", "tbltemp" & Pickbox, "")
bcurrent = DMax("[BSlots]", "tbltemp" & Pickbox, "")
acurrent = DMax("[ASlots]", "tbltemp" & Pickbox, "")
eRem = ecurrent - eUsed
dRem = dcurrent - dUsed
cRem = ccurrent - cUsed
bRem = bcurrent - bUsed
aRem = acurrent - aUsed
eSQL = "UPDATE " & "tbltemp" & Pickbox & " SET [ESlots] = " & eRem
dSQL = "UPDATE " & "tbltemp" & Pickbox & " SET [DSlots] = " & dRem
cSQL = "UPDATE " & "tbltemp" & Pickbox & " SET [CSlots] = " & cRem
bSQL = "UPDATE " & "tbltemp" & Pickbox & " SET [BSlots] = " & bRem
aSQL = "UPDATE " & "tbltemp" & Pickbox & " SET [ASlots] = " & aRem
DoCmd.RunSQL eSQL
DoCmd.RunSQL dSQL
DoCmd.RunSQL cSQL
DoCmd.RunSQL bSQL
DoCmd.RunSQL aSQL
End Sub
Public Function eUse(ePickbox As String) As String
eUse = DCount("[NSlot]", "tbltemp" & ePickbox, "NSlot = 'E'")
End Function
Public Function dUse(dPickbox As String) As String
dUse = DCount("[NSlot]", "tbltemp" & dPickbox, "NSlot = 'D'")
End Function
Public Function cUse(cPickbox As String) As String
cUse = DCount("[NSlot]", "tbltemp" & cPickbox, "NSlot = 'C'")
End Function
Public Function bUse(bPickbox As String) As String
bUse = DCount("[NSlot]", "tbltemp" & bPickbox, "NSlot = 'B'")
End Function
Public Function aUse(aPickbox As String) As String
aUse = DCount("[NSlot]", "tbltemp" & aPickbox, "NSlot = 'A'")
End Function
Static Function PBox()
PBox = InputBox("Please enter the PickBox ID:", "Entry Required")
End Function