I am basically writting a program to assign inventory to a patient. The inventory is being added to the database by checkboxes. So when they click each of the check boxes, 1 is added to each of their equipment signed out. and inventory is decremented by 1 for each equipment.

When the Submit button is clicked everything is added to the DB.


Question:

As I am writting this, I realised if there was 100 pieces of equipment, that would take me forever to write. I am only using 20 equipments--i.e checkboxes. And if the company ever changes their equipment, I would have alot of rewritting to do.

The code below would have to be written for each checkbox selected. Is there a better way?

Here is what I came up with.


VB Code:
  1. [B]//code for the actual checkbox[/B]
  2. Private Sub chkbed_Click()
  3.  
  4. bedchk = False
  5.  
  6. 'vbchecked is a reserved word
  7. chkBed.Value = vbChecked
  8. bedchk = True
  9.  
  10. End Sub
  11. [B]
  12. //adds to the patients equipment in the database[/B]
  13. 'customers only get one thing of each equip
  14. add = 1
  15.  
  16. 'Adding equipment to patient
  17. With rspatientequip
  18. .AddNew
  19.  
  20. id = getCustID
  21.  
  22. !CustId = id
  23.  
  24. If addequip = True Then
  25. !bed = "bed"
  26.  
  27. End If
  28. rspatient.Update
  29. End With
  30.  
  31.  
  32.  
  33. [B]//code for updating inventory[/B]
  34.  
  35. Dim id As String
  36. 'customers only get one thing of each equip
  37. reduce = 1
  38.  
  39.  
  40.  
  41. 'taking away from inventory, Updates inventory field UNitIn Stock - reduce(1)
  42. Dim newDBInstockValue As Integer
  43. Dim dbInStock As Integer
  44.  
  45. With rsinventory
  46.     .MoveFirst
  47.     .Find "ProductName = 'Bed'"
  48.     dbInStock = !UnitInStock
  49.    
  50.     newDBInstockValue = (dbInStock - reduce)
  51.     !UnitInStock = newDBInstockValue
  52.    
  53. rsinventory.Update
  54. End With