Hi,
I am currently generating a list inside a Word 2003 document based on choices made in a userform. Each item has a price so I have set up strings for each one:
VB Code:
Dim strProtectionCoversPrice As String, strChainShortenersPrice, strDetachTopBarPrice As String, _ strFireExtingExtPrice As String, strFireExtingIntPrice As String, strFirstAidKitPrice As String, strFlipUpBarPrice As String, _ strHazChemPrice As String, strHighTippingPrice As String, strHoldToRunPrice As String, strInCabCtrlsPrice As String, _ strLoadCellHangerPrice As String, strLoadCellSubEquipPrice As String, strAddPrinterPrice As String, _ strNetBoxBasic620Price As String, strNetBoxBasic880Price As String, strNetBoxDropDownPrice As String, _ strPressureFilterPrice As String, strRearLightProtectionPrice As String, strRevBuzzerPrice As String, _ strRevCameraPrice As String, strBeaconPrice As String, strHyTowerPrice As String, strWingSPRearBogiePrice As String, _ strWingSRearBogiePrice As String, strWingPRearAxlePrice As String, strWingPRearBogiePrice As String, _ strWingPRearSteerPrice As String, strToolboxPrice As String, strWinchPrice As String, _ strWorkLightSinglePrice As String, strWorkLightTwinPrice As String, strFinishPaintEquipPrice As String strProtectionCoversPrice = "100.00" strChainShortenersPrice = "200.00" strDetachTopBarPrice = "300.00" strFireExtingExtPrice = "400.00" strFireExtingIntPrice = "500.00" strFirstAidKitPrice = "600.00" strFlipUpBarPrice = "700.00" strHazChemPrice = "800.00" strHighTippingPrice = "900.00" strHoldToRunPrice = "50.00" strInCabCtrlsPrice = "1000.00" strLoadCellHangerPrice = "2000.00" strLoadCellSubEquipPrice = "3000.00" strAddPrinterPrice = "300.00" strNetBoxBasic620Price = "100.00" strNetBoxBasic880Price = "110.00" strNetBoxDropDownPrice = "175.00" strPressureFilterPrice = "150.00" strRearLightProtectionPrice = "100.00" strRevBuzzerPrice = "50.00" strRevCameraPrice = "350.00" strBeaconPrice = "50.00" strHyTowerPrice = "1500.00" strWingSPRearBogiePrice = "250.00" strWingSRearBogiePrice = "350.00" strWingPRearAxlePrice = "100.00" strWingPRearBogiePrice = "200.00" strWingPRearSteerPrice = "125.00" strToolboxPrice = "95.00" strWinchPrice = "500.00" strWorkLightSinglePrice = "50.00" strWorkLightTwinPrice = "75.00" strFinishPaintEquipPrice = "900.00"
The contents of the list will vary depending on choices made in a userform. If the items checkbox is not selected, but is enabled, then the item will go in the list:
VB Code:
Dim strProtectionCovers As String, strChainShorteners, strDetachTopBar As String, _ strFireExtingExt As String, strFireExtingInt As String, strFirstAidKit As String, strFlipUpBar As String, _ strHazChem As String, strHighTipping As String, strHoldToRun As String, strInCabCtrls As String, _ strLoadCellHanger As String, strLoadCellSubEquip As String, strAddPrinter As String, _ strNetBoxBasic620 As String, strNetBoxBasic880 As String, strNetBoxDropDown As String, _ strPressureFilter As String, strRearLightProtection As String, strRevBuzzer As String, _ strRevCamera As String, strBeacon As String, strHyTower As String, strWingSPRearBogie As String, _ strWingSRearBogie As String, strWingPRearAxle As String, strWingPRearBogie As String, _ strWingPRearSteer As String, strToolbox As String, strWinch As String, strWorkLightSingle As String, _ strWorkLightTwin As String, strFinishPaintEquip As String, strAvailableOptions As String If chkAddProtectionCovers.Enabled = True And chkAddProtectionCovers.Value = False Then strProtectionCovers = vbCr & chkAddProtectionCovers.Caption & vbTab & "£" & vbTab & strProtectionCoversPrice End If If chkAddChainShorteners.Enabled = True And chkAddChainShorteners.Value = False Then strChainShorteners = vbCr & chkAddChainShorteners.Caption & vbTab & "£" & vbTab & strChainShortenersPrice End If If chkAddDetachTopBar.Enabled = True And chkAddDetachTopBar.Value = False Then strDetachTopBar = vbCr & chkAddDetachTopBar.Caption & vbTab & "£" & vbTab & strDetachTopBarPrice End If If chkAddFireExtingExt.Enabled = True And chkAddFireExtingExt.Value = False Then strFireExtingExt = vbCr & chkAddFireExtingExt.Caption & vbTab & "£" & vbTab & strFireExtingExtPrice End If If chkAddFireExtingInt.Enabled = True And chkAddFireExtingInt.Value = False Then strFireExtingInt = vbCr & chkAddFireExtingInt.Caption & vbTab & "£" & vbTab & strFireExtingIntPrice End If If chkAddFirstAidKit.Enabled = True And chkAddFirstAidKit.Value = False Then strFirstAidKit = vbCr & chkAddFirstAidKit.Caption & vbTab & "£" & vbTab & strFirstAidKitPrice End If If chkAddFlipUpBar.Enabled = True And chkAddFlipUpBar.Value = False Then strFlipUpBar = vbCr & chkAddFlipUpBar.Caption & vbTab & "£" & vbTab & strFlipUpBarPrice End If If chkAddHazChem.Enabled = True And chkAddHazChem.Value = False Then strHazChem = vbCr & chkAddHazChem.Caption & vbTab & "£" & vbTab & strHazChemPrice End If If chkAddHighTipping.Enabled = True And chkAddHighTipping.Value = False Then strHighTipping = vbCr & chkAddHighTipping.Caption & vbTab & "£" & vbTab & strHighTippingPrice End If If chkAddHoldToRun.Enabled = True And chkAddHoldToRun.Value = False Then strHoldToRun = vbCr & chkAddHoldToRun.Caption & vbTab & "£" & vbTab & strHoldToRunPrice End If If chkAddInCabCtrls.Enabled = True And chkAddInCabCtrls.Value = False Then strInCabCtrls = vbCr & chkAddInCabCtrls.Caption & vbTab & "£" & vbTab & strInCabCtrlsPrice End If and so on.....
The list is inserted at a bookmark using another bookmark, that is all the choices, although any null strings will be ignored.
VB Code:
strAvailableOptions = strProtectionCovers & strChainShorteners & strDetachTopBar & _ strFireExtingExt & strFireExtingInt & strFirstAidKit & strFlipUpBar & strHazChem & _ strHighTipping & strHoldToRun & strInCabCtrls & strLoadCellHanger & strLoadCellSubEquip & _ strAddPrinter & strNetBoxBasic620 & strNetBoxBasic880 & strNetBoxDropDown & _ strPressureFilter & strRearLightProtection & strRevBuzzer & strRevCamera & strBeacon & _ strHyTower & strWingSPRearBogie & strWingSRearBogie & strWingPRearAxle & strWingPRearBogie & _ strWingPRearSteer & strToolbox & strWinch & strWorkLightSingle & strWorkLightTwin & strFinishPaintEquip
The method works, but this seems a very long winded and disorganised way of doing things. With a previous and similar problem DKenny kindly provided a solution "building a table on the fly." However, in this instance I have to assign unique price to each item as well so can't see how I can apply that solution.
Any suggestions or pointers would be most welcome. :thumb:
