Results 1 to 10 of 10
  1. #1
    tim_tims33 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Dec 2011
    Posts
    62

    Applying Discount based on membership level - performing calculations in textbox.

    Hi,


    I have an invoice form, where the data source for the invoice is:

    MAIN FORM tblInvoice (InvoiceID, CustomerID,Date)
    tblCustomer (Membership_Level)

    Sub-FORM tblInvoice_Details (InvoiceID, StockID, Qty_Ordered)

    If you look at the attached image, you will see taht i've created an Unbound Textbox (text34) in which i would like to show the discount rate as follows:

    Bronze Member - 15%
    Silver Member - 20%
    Gold Member - 25%

    The membership type is already present (as you can see in the textbox below text34).

    THe issue is this: If a customer is selected in the main form, i would like text34 to be populated with the value 0.15... so then i can use it in the Invoice Total caclculation for applying discount.

    I've tried the following under different events to try and get the value to appear, but it doesn't work.

    [CODE][If Me.txtMember_.Value = "Bronze" Then Me.Text34.Value = 0.15/CODE]

    I've tried BeforeUpdate and AfterUpdate....but i get no value appearing in text34.


    Click image for larger version. 

Name:	INvoice_Form.jpg 
Views:	32 
Size:	86.3 KB 
ID:	19035

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Does this work for you?

    http://www.baldyweb.com/Autofill.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    tim_tims33 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Dec 2011
    Posts
    62
    Unfortunately not. The discount rates are not stored anywhere, except as literals / constants in VBA... i hope.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Not dynamic, but your code should work. Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125
    Quote Originally Posted by tim_tims33 View Post

    [CODE][If Me.txtMember_.Value = "Bronze" Then Me.Text34.Value = 0.15/CODE]
    The code you posted above has an under score that should prevent it from working

    Try this
    Code:
     
    If Me.txtMember.value = "Bronze" then
         Me.Text34.value = 0.15
    Elseif Me.txtMember.value = "Silver" then
         Me.Text34.value = 0.2
    Elseif Me.txtMember.value = "Gold" then
         Me.Text34.value = 0.25
    End if

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    VBA is required only if you want to save the percentage or the calculated value into table. Whether or not this should be done depends on your data structure.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    tim_tims33 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Dec 2011
    Posts
    62
    Still not working. I tried the VB code. no need to store data June... just want to show result of calculation in textbox (textbox34).

    I've attached the DB. The form is frmInvoice. You will see under the calculations for the totals...what i'm trying to do.

    BTW, the code doesn't throw up any runtime errors. Rather, i think, the issue is with the event... which event do i use to run the code.

    I've tried InvoiceID_Change(), BeforeUpdate(), AfterUpdate().

    Any help would be much appreciated. Thanks,tim
    Attached Files Attached Files

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can't look at the sample right now, but I don't think that's the right control. I'd use the after update event of the customer ID, the membership level, and/or perhaps the current event of the form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If you don't want to save the calculated value then why use code? Try IIf() or Switch() expression in textbox:

    =Switch([txtMember]="Bronze", 0.15, [txtMember]="Silver", 0.2, [txtMember]="Gold", 0.25)

    Or in query:

    Switch([Membership_Level]="Bronze", 0.15, [Membership_Level]="Silver", 0.2, [Membership_Level="Gold", 0.25) AS Rate

    Then refer to the constructed field in form or report.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125
    I am unable to open your database
    Gives me a msg unrecognised database...

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Performing Calculations with Recordsets
    By chims in forum Programming
    Replies: 3
    Last Post: 10-22-2014, 10:36 AM
  2. Performing calculations in a form
    By Demerit in forum Forms
    Replies: 9
    Last Post: 12-12-2013, 10:54 AM
  3. Performing calculations from a drop down list
    By snowdrop in forum Queries
    Replies: 5
    Last Post: 01-11-2012, 06:39 AM
  4. Performing calculations in the form.
    By mulefeathers in forum Forms
    Replies: 4
    Last Post: 12-07-2011, 10:47 AM
  5. Replies: 14
    Last Post: 06-03-2010, 06:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums