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:
[B]//code for the actual checkbox[/B] Private Sub chkbed_Click() bedchk = False 'vbchecked is a reserved word chkBed.Value = vbChecked bedchk = True End Sub [B] //adds to the patients equipment in the database[/B] 'customers only get one thing of each equip add = 1 'Adding equipment to patient With rspatientequip .AddNew id = getCustID !CustId = id If addequip = True Then !bed = "bed" End If rspatient.Update End With [B]//code for updating inventory[/B] Dim id As String 'customers only get one thing of each equip reduce = 1 'taking away from inventory, Updates inventory field UNitIn Stock - reduce(1) Dim newDBInstockValue As Integer Dim dbInStock As Integer With rsinventory .MoveFirst .Find "ProductName = 'Bed'" dbInStock = !UnitInStock newDBInstockValue = (dbInStock - reduce) !UnitInStock = newDBInstockValue rsinventory.Update End With




Reply With Quote