Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2004
    Location
    Liverpool - UK
    Posts
    12

    Unanswered: Beginner needs help please! - with if..then..else

    I am a self-taught beginner who is getting to grips with Access – but who can’t yet write in code.

    I have a table which contains, amongst others, three fields – lets say – Gross, Discount and Net. Discount is a fixed percentage of gross.

    I have a form, based on this table for data entry.

    What I want to do is put a tick box on the form for ‘Apply Discount’ and then put a statement somewhere that says

    ‘If [Apply Discount] is true then [Net]=[Gross] minus [Discount]’ and then I want to store the appropriate values in the original table.

    The plan is that ticking the box should automatically fill in the other fields on the form and then store them in the table. If it is not ticked then Discount is zero.

    Problem is I don’t know how – or where- to put the If…then…else statement.

    Can anybody help – or am I being too ambitious for a beginner????

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Problem is I don’t know how – or where- to put the If…then…else statement.

    Can anybody help – or am I being too ambitious for a beginner????
    in my view no, unless you try you never know your limits. And better yet you asked rather than demanded, and furthermore showed willingness to try - go for it......


    you could put some code behind the checkbox apply discount

    right click the checkbox, select properties
    look the events tab and select click

    in the code window
    if checkbox.value=true then 'apply the discount
    'insert your dicosunt code
    else
    'remove your discount code
    endif

    you may need to consider if you need to do something in the forms oncurrent event (this event is triggered when a new record is displayed)

  3. #3
    Join Date
    Feb 2005
    Location
    The Hague, Netherlands
    Posts
    95
    Quote Originally Posted by philw
    I am a self-taught beginner who is getting to grips with Access – but who can’t yet write in code.

    Can anybody help – or am I being too ambitious for a beginner????
    You'll probably want to dig in Access a bit more.. Since I'm a just-started ambitious beginner too, these helped me:

    http://www.functionx.com/access/ (also check the section 'VB Access on the right side of this page for some VBA-coding tutorials)
    http://mis.bus.sfu.ca/tutorials/MSAccess/tutorials.html
    http://cma.zdnet.com/book/masteringaccess/index.htm

  4. #4
    Join Date
    Jul 2004
    Location
    Southampton, UK
    Posts
    368
    Phil

    Consider how your tick box is going to work. I assume it isn't bound to your record source (linked to your table). So when you tick it an event such as one suggested by healdem will do what you want for that record. But what do you want to happen when you move to the next (or previous) record. The tick box will still hold the same value so if it had been ticked for the previous record, it will still be ticked regardless of whether the current record should have discount or not - so it looks inconsistent to the user. This is probably what healdem is referring to when he mentions OnCurrent. On this basis I would not use a tick box like this.

    Either:
    Use a button to calc and set the required value (and then perhaps have another button to clear it). You could even have a simple message to auto display if the discount is non-zero

    Or:
    Store the tick box (yes/no field) in your table. You then don't need to store the result [Net] (and should not anyway) as this can always be calculated based on the value of your tick box and [Gross] and [Discount].

    Chris

  5. #5
    Join Date
    Sep 2004
    Location
    Liverpool - UK
    Posts
    12
    Thanks to you all for your suggestions. Will try them!

Posting Permissions

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