Ask Your Question

assigning $ values to 5 checkboxes that can show total $ in a textbox

asked 2019-02-28 01:28:26 +0200

weaverman55 gravatar image

updated 2020-08-09 00:04:52 +0200

Alex Kemp gravatar image

I have a form with 5 check boxes that i would like to have dollar amounts assigned to so if a checkbox is checked a dollar amount will show up in a textbox. The more check boxes checked the textbox dollar amount would increase. Picture of form attached. Please know that i am a senior citizen with limited computer experience but have been able to get a odb made and a form started. Any help or direction would be greatly appreciated. Thanks in advance.C:\fakepath\Screen Shot 2019-02-27 at 6.24.22 PM.png

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2019-02-28 03:58:03 +0200

Ratslinger gravatar image


Contrary to common sense, have attached your sample from previous question with a macro to update 'Shipping Cost' field.

You have not followed my comment about including ...a great amount of details as requested in the comments. Here are just a few of the problems as seen:

  • How are amounts determined

  • Where to place the result

  • Is there a base charge

  • Once the record is saved there is no record of what was actually applied

  • Can both single & double box be selected

  • What if an item needs to be applied more than once - labels; 2X bubble wrap; double foam

This is just the surface of potential problems. There was little thought put into posting this question or possibly designing what is really needed to complete the task.

Here is the code used in the Base file:

Option Explicit
Sub CalculateShipping
    Dim oForm           As Object
    Dim oColumns        As Object
    Dim bBubbleWrap     As Boolean
    Dim bSingleBox      As Boolean
    Dim bDoubleBox      As Boolean
    Dim bFoam           As Boolean
    Dim bLabels         As Boolean
    Dim dBaseShipping   As Double
Rem Gets Main internal form
    oForm = ThisComponent.Drawpage.Forms.getByName("MainForm") 'Get Form
Rem Check if checkboxes selected
    bBubbleWrap = oForm.getByName("Bubble Wrap").getCurrentValue()
    bSingleBox = oForm.getByName("Single Box").getCurrentValue()
    bDoubleBox = oForm.getByName("Double Box").getCurrentValue()
    bFoam = oForm.getByName("Foam").getCurrentValue()
    bLabels = oForm.getByName("Labels").getCurrentValue()
Rem Initial shipping price
    dBaseShipping = 0.00
Rem Add shipping if item selected
    if bBubbleWrap Then
        dBaseShipping = dBaseShipping + 0.25
    End If
    if bSingleBox Then
        dBaseShipping = dBaseShipping + 0.75
    End If
    if bDoubleBox Then
        dBaseShipping = dBaseShipping + 1.25
    End If
    if bFoam Then
        dBaseShipping = dBaseShipping + 0.45
    End If
    if bLabels Then
        dBaseShipping = dBaseShipping + 0.25
    End If
Rem Obtain and update Shipping Cost field
    oColumns = oForm.getColumns()
    oColumns.getByName("Shipping Cost").updateDouble(dBaseShipping)
End Sub

This was kept very simple because as you stated you have no knowledge in this area. You can see the amounts applied. Those need to be changed accordingly.

Sample-------- ReelToReelModified.odb

There certainly may be better methods to accomplish what is needed but have no real idea what is to be accomplished and certainly no details were provided. This may well have been done without macros by using a secondary table, saving certain data and using SQL to produce totals.

Finally, LO documentation (including some on macros) can be found here -> LibreOffice Base Handbook.

edit flag offensive delete link more


First off thanks for all your help. Secondly i'm sure you deal with very complex aspects of forms for wanting a lot of detail but my form as i detailed in my question is just the opposite, very basic. 5 check boxes with one or more checked with no multiples. Appreciate the help.

weaverman55 gravatar imageweaverman55 ( 2019-02-28 14:57:00 +0200 )edit

@weaverman55 You are welcome and hope you got what you wanted.

Most questions dealing with forms are even more basic than what you have presented. However, as I tried to point out, from experience, it is riddled with potential problems. Have seen this too many times in the past. That is why, as asked for in your question, I have tried to explain why more planning is possibly needed. Have seen similar situations where 3 to 6 months later everything needed to be re-done because the original design was lacking data saved. A point being, in the future if you need to go back to a record, how can you possibly reconcile 'Shipping Cost' since what was originally checked is no longer available let alone that the actual amounts may now be different. This has nothing to do with form complexity but rather on logic.

Just trying to help as you asked.

Ratslinger gravatar imageRatslinger ( 2019-02-28 16:58:36 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-02-28 01:28:26 +0200

Seen: 47 times

Last updated: Feb 28 '19