Results 1 to 5 of 5

Macro help

  1. #1
    k11ngy is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2012
    Posts
    12

    Macro help

    Hi



    My students have an exam soon. They have to learn below, which I can show them but of course will hey remember. I was given the code but wanted to know easy way to build this code rather than have to remember it without a handout to help

    Appreciate help

    Regards

    Steve

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    14,219
    Steve,
    Suggest you give us something to work with. Perhaps you hit the save button a little early???

  3. #3
    k11ngy is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2012
    Posts
    12
    Apologies

    Option Compare Database

    Private Sub updateDonorRecord_Click()
    updatedDonations = CurrentTotal + DonationAmount
    If updatedDonations < 26 Then
    updatedStatus = "Bronze"
    ElseIf updatedDonations < 51 Then
    updatedStatus = "Silver"
    ElseIf updatedDonations < 76 Then
    updatedStatus = "Gold"
    Else: updatedStatus = "Platinum"
    End If

    End Sub

    Quote Originally Posted by k11ngy View Post
    Hi

    My students have an exam soon. They have to learn below, which I can show them but of course will hey remember. I was given the code but wanted to know easy way to build this code rather than have to remember it without a handout to help

    Appreciate help

    Regards

    Steve

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    6,206
    A few comments if I may:
    - that isn't a macro, it's a procedure - specifically a private sub. Granted, in Excel, these are referred to as macros, but that has an entirely different context in Access
    - learning vba code is a long curve for most of us. There is no magic bullet for replicating such events as this. You need to know the properties and methods of an object in order to write code for it, or you resort to macros, which have their limitations. Experienced developers don't use macros 99.5% of the time.
    - I presume you're showing the top of the module code because I see Option Compare. Every module should have Option Explicit at the top or else you deserve the trouble you get. This is an option in vb editor "Require variable declaration". On the subject of variable declaration, you appear to be using variables that have not been declared.
    - it is generally considered to be bad design to store calculations, but I can't be sure if that is the case here as we don't know what updateddonations is
    - pretty sure this is incorrect - Else: The colon will make this a line label and it will never execute
    - there are other potential issues, such as if updateddonations is null, none of these status values will be applied
    - lastly in reference to your post, please use code tags (#) and indentation when posting code. It makes it easier to read.
    - "doesn't work" is no help. Post err msgs and where.
    - Use code tags for code/sql. Implement changes in copies of your database.

  5. #5
    k11ngy is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2012
    Posts
    12
    Thank you and appreciate feedback, time for me to get some training

    Thanks again



    Quote Originally Posted by Micron View Post
    A few comments if I may:
    - that isn't a macro, it's a procedure - specifically a private sub. Granted, in Excel, these are referred to as macros, but that has an entirely different context in Access
    - learning vba code is a long curve for most of us. There is no magic bullet for replicating such events as this. You need to know the properties and methods of an object in order to write code for it, or you resort to macros, which have their limitations. Experienced developers don't use macros 99.5% of the time.
    - I presume you're showing the top of the module code because I see Option Compare. Every module should have Option Explicit at the top or else you deserve the trouble you get. This is an option in vb editor "Require variable declaration". On the subject of variable declaration, you appear to be using variables that have not been declared.
    - it is generally considered to be bad design to store calculations, but I can't be sure if that is the case here as we don't know what updateddonations is
    - pretty sure this is incorrect - Else: The colon will make this a line label and it will never execute
    - there are other potential issues, such as if updateddonations is null, none of these status values will be applied
    - lastly in reference to your post, please use code tags (#) and indentation when posting code. It makes it easier to read.

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

Similar Threads

  1. Replies: 3
    Last Post: 07-19-2017, 12:40 PM
  2. Replies: 7
    Last Post: 01-20-2017, 02:21 PM
  3. Replies: 1
    Last Post: 01-13-2015, 01:33 PM
  4. Replies: 2
    Last Post: 05-05-2012, 02:34 AM
  5. Replies: 0
    Last Post: 01-12-2011, 12:43 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
  •  
Tech Forums: Microsoft Office Forums