Discussion Locked

Access 2000: Compare Fields

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a access database with a Order form. On the form I have the following: Style, Color, S, M, L, XL, XXL. Style & color are pull down, qty is entered into the others. When an entry is made into one of the size fields, I would like it to compare that number to the actual colorinventory(table name: colorinventory) number to determine if the size will be backordered, then disply a message stating that a backorder will happen.
Thanks for the help.

3 replies

by peyison

Not sure how your table is set up, but you might try something like:

'--the Before Update event of one of your text boxes
tbxXL_BeforeUpdate(Cancel as Integer)
Dim sStyle as String
Dim sColor as String
Dim sSql as String
Dim iQty as IntegerDim iAmtOnHand as Integer
Dim db as Database
Dim rst as Recordset

'--get the style from the Style combo box
sStyle = cbxStyle

'--get the color from the Color combo box
sColor = cbxColor

'--get the quantity entered in this textbox
iQty = tbxXL

'--create the query from the above values - size will change for each textbox (could put this in a function that each text box calls)
sSql = "Select AmtOnHand From ColorInventory Where Style = '" & sStyle & "' and Color = '" & sColor & "' and Size = 'XL'"

'--create instances of the db and recordset
Set db = DBEngine(0)(0)
Set rst = db.OpenRecordset(sSql, dbOpenDynaset)

iAmtOnHand = rst!AmtOnHand

rst.close
set rst = nothing
set db = nothing

'check the quantities, and display a message if needed (could include color and stlye in the message)
If iAmtOnHand < iQty Then
msgbox "There are only " & iAmtOnHand & " XL shirts in inventory. " & iQty-iAmtOnHand & " will have to be backordered."

End Sub

Hope this helps.

This discussion is closed to new replies.