Results 1 to 10 of 10
  1. #1
    noaccessguru is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    Melbourne, Australia
    Posts
    68

    After Update event help

    Hi All,



    Hoping someone can help me out! (I’m using Access 2010)

    I have a Form where a user will enter information, and I want the ‘Status’ field to update based on the selection of ‘Type’ (which is a Combo Box.)

    So if a user selects the Type ‘Permit’ I want the Status field to automatically update to ‘Open’.
    If they select the Type ‘Concession’ I want the Status field to automatically update to ‘Closed’
    If they select the Type ‘Trial’ I want the Status field to automatically update to ‘Closed’

    How do I write this in VBA as an ‘After Update’ event??

    I seem to be getting stuck



    Also, one additional thing, can I have the ‘Status’ automatically update to ‘Expired’ if the ‘Expiry Date’ field has passed? How would I write this?

    (Thanking you in advance.....as I am not very good at VBA yet!)

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Why you do even need the Status field? If Permit always means Open and Concession/Trial always mean closed, an expression in query or textbox will serve:

    IIf([Type]="Permit", "Open", "Closed")
    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.

  3. #3
    noaccessguru is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    Melbourne, Australia
    Posts
    68
    Thanks JUne7, but please excuse my ignorance....again Im not a master with Access!

    So I don't need to display that field at all on the data entry page you mean? then in which field do I put that code? (I hope I am making sens)

    Eventually, the user will come in and 'Edit' that record and change the 'Open' ones to Closed etc when they are ready.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    You want to allow user to change the Status regardless of what the Type is? Okay, then need field in table. Allow the code to set Status only if Status field is null. Put code in the Type combobox AfterUpdate event. In the event property select [Event Procedure], click the ellipses (...), type code in the procedure.

    If IsNull(Me!Status) Then Me!Status = IIf([Type]="Permit", "Open", "Closed")
    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.

  5. #5
    noaccessguru is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    Melbourne, Australia
    Posts
    68
    BEAUTIFUL!!! Thanks June7, this is exactly what I was after and works great!

    Thanks alot of your help

  6. #6
    noaccessguru is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    Melbourne, Australia
    Posts
    68
    Hi June7 (hopefully you see this)

    In addition to this, I have an 'Expiry Date' field, is it possible to make the 'Status' field in the table update to 'Expired' once the date has passed? With an On Load event or something?
    If so, how do I write this?

    Not sure if it is posible or not..or should i be creating an update query to update this field and use a macro or code or something to execute the query when the database is opened?
    Last edited by noaccessguru; 08-07-2013 at 10:44 PM. Reason: Updates added

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Yes, that is possible. Like:

    If Me![Expiry Date] > Date() Then Me!Status = "Expired"

    But that will only run when for the specific record opened in form. If you don't open a record for weeks after the expiration then data will be way out of date and your reports may be in error.

    So you probably want to run a procedure daily that would update entire table. Do you have a form (like a Main Menu) that opens automatically when db starts? Can have code in that form Open or Load event if you want it that automated or a have a button:

    CurrentDb.Execute "UPDATE tablename SET Status='Expired' WHERE [Expiry Date]>Date();"
    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.

  8. #8
    noaccessguru is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    Melbourne, Australia
    Posts
    68
    Yeah I have a form (FrmHomePage) that opens when you open the database. So I would ideally would like it to run when this Loads as I wont be the one using the database as much so dont want to have an extra step where another button is required tp be pushed.

    So I just need to copy the code exactly as you have written it above 'On Load' event (in VBA) for this form? (obviously updating with my table/field name?)...or is this a code for a Macro or Expression Builder?

    (again sorry!)

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    That is VBA. There is macro equivalent but I don't use macros.

    Minor but critical correction, use apostrophes around Expired instead of quote marks. I have fixed the post to reflect.
    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
    noaccessguru is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    Melbourne, Australia
    Posts
    68
    Awesome thanks June7.....I was getting an error before when I was copying it into VBA, but it seems to be working a treat now!

    Thanks again!

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

Similar Threads

  1. Using event to update corresponding fields
    By rossi45 in forum Forms
    Replies: 1
    Last Post: 05-02-2012, 01:29 AM
  2. Before Update Event Help
    By bklewis in forum Access
    Replies: 8
    Last Post: 03-25-2012, 03:58 PM
  3. Before Update Event
    By randolphoralph in forum Programming
    Replies: 0
    Last Post: 06-15-2010, 09:26 AM
  4. Syntax For After Update Event
    By MuskokaMad in forum Forms
    Replies: 14
    Last Post: 03-12-2010, 01:48 PM
  5. Befor update event
    By wasim_sono in forum Forms
    Replies: 1
    Last Post: 03-24-2006, 07:21 AM

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