Results 1 to 4 of 4

Thread: New to VBA

  1. #1
    Join Date
    May 2004
    Posts
    7

    Unanswered: New to VBA

    Hi all

    as the title suggests im new to VBA and need a little help and a push in the right direction

    i have the following in a from

    Number of Bottles
    Price per Bottles
    Total
    Discount
    Grand Total

    if more then 12 bottles are ordered i need to apply a 12.5 % to the grand toal, and show the discount given in the discount box, if the order is 11 bottles are less then i need the discount box to stay blank,

    i have started writing something along the lines of
    Private Sub Grand Total_AfterUpdate()
    If Me.Number_of_Bottles >= "12" Then Me.Total -"12.5%"

    but that doesnt work, and im truely stuck, so any help please??

    thank you for your time

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hello there

    I don't entirley get what you're trying to do, but I think I can help with some things and then you could clear me up on others.
    Firstly, shouldn't the code execute after the number_of_bottles AfterUpdate event since the test is on this value? Then change

    If Me.Number_of_Bottles >= "12" then

    to

    If Me.Number_of_Bottles >= 12 then

    I don't know what "apply a 12.5 % to the grand total" means, but I have a suspicion we are talking about discounts on a case of wine, in which case to apply a 12.5% discount you would want to do something like:

    Me.Total = me.total * 0.875

    (This assumes you have calculated the total cost separately)
    So - I would say the code should be:

    Number_of_Bottles_AfterUpdate()

    If Me.Number_of_Bottles >= 12 then

    Me.Total = me.total * 0.875
    me.discount = "12.5%"

    else

    me.discount = ""

    end if

    Actually, I have no questions now I've worked though it - just let us know if I've missed something

    Cheers
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    What sort of layout are you using to enter these orders? If you are using a subform, you could evaluate the current record count of the form and add a value accordingly. This could be fired in the after update event of the form, using code similar to this:
    Code:
    If Me.RecordCount >= Then
       'add additional percentage here
    End If
    This is of course only a slight variation on the above poster's suggestion.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  4. #4
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    IIF([NumberBottles]>12,[Price]*.875,[Price]) for the field to show price

    IIF ([NumberBottles]>12,12.5,Null) for the field to show discount

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •