+ Post New Thread
Results 1 to 6 of 6
Office Software Thread, Access - Conditional Macros in Technical; Hi, I've got a Macro assigned to a button on a form which is a query output. When the user ...
  1. #1

    garethedmondson's Avatar
    Join Date
    Oct 2008
    Location
    Gowerton, Swansea
    Posts
    2,263
    Thank Post
    965
    Thanked 324 Times in 192 Posts
    Blog Entries
    11
    Rep Power
    165

    Access - Conditional Macros

    Hi,

    I've got a Macro assigned to a button on a form which is a query output. When the user clicks on the button it reads a value from a field and subtracts 150. It puts the new value back into that field.

    I have done this with a Macro

    The Macro looks like this:

    GoToControl Points Balance
    SetValue [Forms]![frm_qry_choose_gift]![Point Balance], [Forms]![frm_qry_choose_gift]![Point Balance]-150

    I'm looking to get some sort of conditional rule in there which reads the users points value and if they have less than 150 runs another Macro (or stops this Macro) that tells them they cannot continue.

    Can anyone offer advice getting the conditional rule in there? I could use code but for this scenario it has to be a macro.

    The pseudocode I want to follow is:

    runMacro
    If button1 is clicked then
    read guest_points
    if guest_points is less than 150 then
    run errormessageMacro
    else
    continue running the subtraction and field update to remove 150 points.

    Any help is appreciated,

    Many thanks

    Gareth
    Attached Images Attached Images

  2. #2

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    11,186
    Thank Post
    875
    Thanked 2,717 Times in 2,302 Posts
    Blog Entries
    11
    Rep Power
    780
    This may help:
    ACC2000: How to Use a Conditional Macro to Confirm Changes to a Field

    The ellipsis in the Condition column forces Microsoft Access to perform the action on that line if the condition on the preceding line is true
    so adding them to the macro actions that you already have (in screenshot) to be performed if the condition is true should make it work.
    Last edited by SYNACK; 26th January 2009 at 10:23 PM.

  3. Thanks to SYNACK from:

    garethedmondson (26th January 2009)

  4. #3

    garethedmondson's Avatar
    Join Date
    Oct 2008
    Location
    Gowerton, Swansea
    Posts
    2,263
    Thank Post
    965
    Thanked 324 Times in 192 Posts
    Blog Entries
    11
    Rep Power
    165
    Hi,

    This one is bugging me now. I have put in a line with ... but even though the points are not there and we get the error message, it is still carrying on to remove the points - moving the user into minus points.

    This time I have removed the msgbox commands as they were just there for me to see how far the macro had progressed.

    So I have the first condition which checks to see if the user is less than 150 points. This works and gives the error message and stops the macro. However if the condition is false and the user has more than 150 points then the macro does not run.

    Screenshot attached.

    Gareth
    Attached Images Attached Images
    Last edited by garethedmondson; 26th January 2009 at 10:38 PM.

  5. #4

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    11,186
    Thank Post
    875
    Thanked 2,717 Times in 2,302 Posts
    Blog Entries
    11
    Rep Power
    780
    I think it is the blank lines causing the issues, you should have something like this without the blank conditionals or blank actions:

    Condition | Action
    <150 | MsgBox
    ... | StopMacro
    > 150 | GoToControl
    ... | SetValue
    ... | StopMacro

  6. Thanks to SYNACK from:

    garethedmondson (26th January 2009)

  7. #5

    garethedmondson's Avatar
    Join Date
    Oct 2008
    Location
    Gowerton, Swansea
    Posts
    2,263
    Thank Post
    965
    Thanked 324 Times in 192 Posts
    Blog Entries
    11
    Rep Power
    165
    Yes that is correct. I've just hunted out my Access for Dummies book and on page 470 is exactly what you described.

    I added it and it worked. I then saw your posting.

    Brilliant. That works. Not to move on....

    Incidentally on dbforums.com I've been told that code is the best way to do this - even though I don't want to use code at the moment.

    Amazing what you find on the web.

    Many thanks once again

    Gareth

  8. #6

    garethedmondson's Avatar
    Join Date
    Oct 2008
    Location
    Gowerton, Swansea
    Posts
    2,263
    Thank Post
    965
    Thanked 324 Times in 192 Posts
    Blog Entries
    11
    Rep Power
    165
    How correct is the code producted by the 'Convert Macro to VBA' option?

    I've started looking at the code in an attempt to increase the functionality of my exemplar project. The code looks easy enough to understand - but is this a good way to learn?

    Does the conversion offer 'proper' VBA code?

    GJE

SHARE:
+ Post New Thread

Similar Threads

  1. M$ Access
    By Hightower in forum How do you do....it?
    Replies: 5
    Last Post: 15th June 2008, 06:15 PM
  2. Conditional formatting help needed
    By Jobos in forum How do you do....it?
    Replies: 3
    Last Post: 3rd June 2008, 01:58 PM
  3. Help with conditional formatting
    By randle in forum Windows
    Replies: 3
    Last Post: 25th October 2007, 01:20 PM
  4. Mandatory Profiles and Macros
    By Midget in forum Windows
    Replies: 3
    Last Post: 24th January 2007, 05:07 PM
  5. MS Access
    By wesleyw in forum How do you do....it?
    Replies: 1
    Last Post: 9th November 2006, 09:50 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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