Validatidating if a value is a multiple of another value

JonCraver

New Member
Joined
Dec 8, 2008
Messages
5
I'm trying to build a simple order entry screen. I have an Item Table with a field representing the minimum qty that can be ordered for each item. In the order entry screen, I have a field to enter the qty the customer orders.

I need a code to validate or automatically change the qty ordered to a multiple of the minimum qty.

For example:

If the Minimum_Qty is 3,
The value of the Qty_Ordered needs to be a multiple of 3.

If the user tries to enter 2, i want a window to pop up saying to qty must be a multiple of (the minimum for the item entered) or for the value to automatically round up to the nearest multiple of the minimum.

any help on this?
 
Here is something very basic to get you started

Code:
Private Sub Text1_AfterUpdate()
Dim MinQty As Long, ItemNum As String, OrdQty As Long
OrdQty = Me.Text1.Value
ItemNum = Me.Combo0.Value
MinQty = DLookup("MinQty", "Table1", "Item='" & ItemNum & "'")

If OrdQty Mod MinQty <> 0 Then
    MsgBox OrdQty & " is not a multiple of " & MinQty & ". Quantity will be rounded up.", vbExclamation, "Oops!"
    Do Until OrdQty Mod MinQty = 0
        OrdQty = OrdQty + 1
    Loop
    Me.Text1.Value = OrdQty
End If
End Sub

This example assumes the following, so you will need to update it to suit your database
- Table1 is your table with one field named Item and another named MinQty.
- The form has a combo box (Combo0) which contains a listing of all Items from Table1
- Text1 is where the user enters the order quantity

After the user enters the order quantity, the code checks to see if dividing it by the minimum quantity returns a remainder of 0. If it doesn't, then it's not a multiple, and the amount will be rounded up.
 
Upvote 0
You could also set up the combo so that once you select an item, the minimum quantity is inserted.
Say cboItem has these 4 fields:
ItemID
ItemDescription
ItemPrice
MinQty

You want to push MinQty to OrderQty.

In the AfterUpdate event of the combo, put this:

Me.OrderQty = Me.cboItem.Column(3)

Because the numbering starts from 0, that's the fourth column.

Denis
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top