I am using Access 97 (I know) and am creating a lost and found database for materials in our company. I have it all set up so an employee can enter a sales order and pick a specific line/multiple lines from that sales order to choose what has been lost. If the quantity of the Sales order line is 30, they can choose with an input box how many was lost.
My problem is, if the quantity of the sales order is 30, they can still say they lost 40 - which is an obvious problem. If they put in more than what is possible to be lost, I need a message box to explain what they did and then for the input box to appear again and ask them how many was lost. I can get this to happen once, but if they put a greater number again, it just accepts it. I've messed around with lots of VBA, but here is what I have at the moment for just this section.
For Informational purposes....lst bxLostItems has all of the info from the sales order. They can multi select to choose multiple items that are lost. I have invisible text boxes (the controls that start with lst) that will be used to insert into a table. lstQtyLost is the text box that needs to be equal or less than lstbxLostItems. Column (5,i). I hope that helps.
The Bold and Italics section is what I've tried. It didn't work so I've commented it out for now. My message box wouldn't appear and the input box would contine to ask sometimes and then all of the sudden not show up, even though I would continue to enter a quantity greater than was on the sales order.
I hope this all makes sense. I just need the input box to say "there were XXX total on the order. How many were lost?" And not accept any answer that is greater than XXX. Please help any way you can and ask any questions you need to. Thanks a ton.
Dan.
My problem is, if the quantity of the sales order is 30, they can still say they lost 40 - which is an obvious problem. If they put in more than what is possible to be lost, I need a message box to explain what they did and then for the input box to appear again and ask them how many was lost. I can get this to happen once, but if they put a greater number again, it just accepts it. I've messed around with lots of VBA, but here is what I have at the moment for just this section.
For Informational purposes....lst bxLostItems has all of the info from the sales order. They can multi select to choose multiple items that are lost. I have invisible text boxes (the controls that start with lst) that will be used to insert into a table. lstQtyLost is the text box that needs to be equal or less than lstbxLostItems. Column (5,i). I hope that helps.
Code:
Dim i
If Me.lstbxLostItems.Visible = True Then
For i = 0 To Me.lstbxLostItems.ListCount - 1
If Me.lstbxLostItems.Selected(i) Then
Me.lstDeliveryNumber = Me.lstbxLostItems.Column(1, i)
Me.lstDLineItem = Me.lstbxLostItems.Column(2, i)
Me.lstDLineItem = Format(Me.lstDLineItem, "000000")
Me.lstSalesOrder = Me.lstbxLostItems.Column(3, i)
Me.lstSLineItem = Me.lstbxLostItems.Column(4, i)
Me.lstSLineItem = Format(Me.lstSLineItem, "000000")
Me.lstMaterialNumber = Me.lstbxLostItems.Column(6, i)
Me.lstMaterialNumber = Format(Me.lstMaterialNumber, "000000000000000000")
Me.lstMaterialDescription = Me.lstbxLostItems.Column(7, i)
Dim strInput As String, strMsg As String
If Me.lstbxLostItems.Column(5, i) = 1 Then
Me.lstQtyLost = 1
Else
strMsg = "The quantity of material " & Me.lstbxLostItems.Column(6, i) & " " & Me.lstbxLostItems.Column(7, i) & " on the Sales Order was " & Me.lstbxLostItems.Column(5, i) & ". How many were lost?"
strInput = InputBox(Prompt:=strMsg, Title:="Quantity Lost")
Me.lstQtyLost = strInput
[B][I]'If Me.lstQtyLost > Me.lstbxLostItems.Column(5, i) Then
' Do Until Me.lstQtyLost <= Me.lstbxLostItems(5, i)
' MsgBox ("You entered " & Me.lstQtyLost & " as lost but there are only " & Me.lstbxLostItems.Column(5, i) & " of Material " & Me.lstbxLostItems.Column(6, i) & " " & Me.lstbxLostItems.Column(7, i) & " on the order. Please enter a new quantity.")
' strInput = InputBox(Prompt:=strMsg, Title:="Quantity Lost")
' Me.lstQtyLost = strInput
' If Me.lstQtyLost <= Me.lstbxLostItems.Column(5, i) Then Exit Do
'Loop
'Else
'End If[/I][/B] End If
DoCmd.RunSQL ("INSERT INTO LostDetail (LDLostHeaderID, LDCustomerName, LDSalesOrder, LDSLineItem, LDDeliveryNumber, LDDLineItem, LDMaterialNumber, LDMaterialDescription, LDTotalLost, LDStillLost, LDWhenLost) VALUES ([Forms]![FrmLostItems]![txtLostNumber],[Forms]![FrmLostItems]![txtCustomerName],[Forms]![FrmLostItems]![lstSalesOrder],[Forms]![FrmLostItems]![lstSLineItem],[Forms]![FrmLostItems]![lstDeliveryNumber],[Forms]![FrmLostItems]![lstDLineItem],[Forms]![FrmLostItems]![lstMaterialNumber],[Forms]![FrmLostItems]![lstMaterialDescription],[Forms]![FrmLostItems]![lstQtyLost],[Forms]![FrmLostItems]![lstQtyLost],[Forms]![FrmLostItems]![txtDateLost])")
Else
End If
Next i
I hope this all makes sense. I just need the input box to say "there were XXX total on the order. How many were lost?" And not accept any answer that is greater than XXX. Please help any way you can and ask any questions you need to. Thanks a ton.
Dan.
Comment