Morning all. Hopefully i can explain this issue clearly. In brief i have loop 1 with loop 2 occuring within it. Loop 2 has to continue until the correct value is input but if a incorrect value is input i want the vba to stop let the user enter a new value click ok to check and then continue to complete the rest of loop 1 if the value is correct. I can get this to kinda work by using the following vba for loop 2
The issue i have with this though is that it is a pop up message box i would like this to occur on the form. Hopefully that is clear. below is my entire code anyway just incase
Thanks for any respnce in advance
Code:
Do
strLoc = InputBox("Please scan the location")
Loop Until strLoc = l
Code:
RUN THRU TIL BUTTON
Private Sub btnLocOK_Click()
Dim l As Integer
Dim strQuery As String
strQuery = "SELECT OrderID, ProdID, Quantity, ItemID FROM Item WHERE OrderID = " & Me.cboOrderID
Set db = CurrentDb
Set rs = db.OpenRecordset(strQuery)
While Not rs.EOF
o = rs!OrderID
p = rs!ProdID
q = rs!Quantity
item = rs!ItemID
For i = 1 To q
Me.txtOrder = ""
Me.txtProd = ""
Me.txtLoc = ""
strOrder = ""
strProd = ""
strLoc = ""
'SQL to find the rack location with the oldest stock what is required for the order
strOldestStockSQL = "SELECT [Location].RackID" & _
" FROM Location" & _
" WHERE [Location].ProdID = " & p & _
" AND [Location].StockAge = " & _
" (SELECT MIN(StockAge) FROM Location " & _
" WHERE [Location].ProdID = " & p & ");"
'takes the first rack location if thier are multiple locations
l = CurrentDb.OpenRecordset(strOldestStockSQL).Collect(0)
'PRINT VALUES ONTO FORM
'ORDER
strOrder = strOrder & o
Forms!frmPickOrder!txtOrder = strOrder
'PROD
strProd = strProd & p
Forms!frmPickOrder!txtProd = strProd
'LOCATION
strLoc = strLoc & l
Forms!frmPickOrder!txtLoc = strLoc
'THE BELOW BIT HERE IS THE LOOP 2
'///////////////////
Do
strLoc = InputBox("Please scan the location")
Loop Until strLoc = l
'//////////////////
'MsgBox "Correct location scanned"
'Prevents any users going any further unless they scan the correct location
'At this point the pallet tag would now be re-written to match the order number
MsgBox "Please scan the pallet"
MsgBox "Tag changed"
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tblAllocate ([ItemID], [RackID]) VALUES (" & item & ", " & l & ");"
DoCmd.RunSQL "UPDATE [Location] SET [Location].ProdID = 1 WHERE [Location].RackID =" & l
DoCmd.SetWarnings True
Next i
rs.MoveNext
Wend
'When a order is completed the notes will be printed off in the office.
DoCmd.OpenReport "rptPickOrder", acViewPreview, , "OrderID like '*" & o & "*'"
'Completes the pick so it now will not display on the users screen
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE [Order] SET [Order].Picked = True WHERE [Order].OrderID =" & o
DoCmd.SetWarnings True
'REFRESH ALL SCREENS AND DROP DOWNS
Me.cboOrderID.Requery
Me.cboOrderID.Value = Null
Me.txtOrder = ""
Me.txtProd = ""
Me.txtLoc = ""
strOrder = ""
strProd = ""
strLoc = ""
Comment