Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Anna987 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    22

    Trigger event by changing field programmaticly

    Hello,



    When i manualy change the value of a field in a form then the event 'afterupdate' of that field will be triggered.
    What i want to do is change the value of that field by writing a value to it programmaticly (so not by typing in to the field)
    When the value changes then i want to run a function.
    How do i to this ....?

    Thanks in advance,

    Bieke

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,934
    If by ‘writing to it’ you mean using vba then extend the vba to compare the existing value with the new value the vba is providing

    something like

    Code:
    if newvalue<>controlname then
      controlname=newvalue
      call function 
    End if

  3. #3
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    The other option is a data macro, which acts at a table level, depending on what's required.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    Anna987 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    22
    Quote Originally Posted by CJ_London View Post
    If by ‘writing to it’ you mean using vba then extend the vba to compare the existing value with the new value the vba is providing

    something like

    Code:
    if newvalue<>controlname then
      controlname=newvalue
      call function 
    End if
    WIth writing to it i mean by using a button write a value to the field ([field] = 5)
    How can i execute the function if newvalue <>controlename .......

  5. #5
    Anna987 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    22
    WIth writing to it i mean by using a button write a value to the field ([field] = 5)
    How can i execute the function if newvalue <>controlename .......

  6. #6
    ano is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2023
    Posts
    204
    question : what / why is there a difference between type into the field and use button to put value into the field?
    my logic would be : in on_change event from the field put the function you want to use if there is a change in the field.
    if it realy only need to run from the button , put cj_london's code into the on_click from the button

  7. #7
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,934
    not sure how simpler it can be

    Code:
    if 5<>controlname then
      controlname=5
      call function 
    End if
    Be clear about whether you are talking about controls on a form or fields in the form recordset.

  8. #8
    Anna987 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    22
    The difference is that the event will not be executed when you write a value to a controlfield, only if you TYPE it in the field the event AfterUpdate will be executed.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,557
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Anna987 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    22
    I'm sorry. Is it not allowed to post on different forums? I try to find as many ideas ...

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,557
    Quote Originally Posted by Anna987 View Post
    I'm sorry. Is it not allowed to post on different forums? I try to find as many ideas ...
    No per se, but considered good manners to inform users of the fact, as advice can get repeated and people are wasting their time repeating what has already been offerred, as has happened in this case with regard to data macro.
    You have been here since 2015 and 2017 on that other forum, so should be aware in all that time.
    Just inform people when you do so please.
    Last edited by Welshgasman; 09-03-2024 at 11:45 AM.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #12
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,934
    The difference is that the event will not be executed when you write a value to a controlfield, only if you TYPE it in the field the event AfterUpdate will be executed.
    I am well aware of that - the code I provided would be put in your button click event since this is what you appear to be using per post#4

  13. #13
    Anna987 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    22
    Quote Originally Posted by CJ_London View Post
    I am well aware of that - the code I provided would be put in your button click event since this is what you appear to be using per post#4
    Hello CJ,

    i understand that it is a little confusing how i try to make myself clear.
    I mensioned the button to explain my problem the easy way but this is my explanation of the exact problem.
    In fact there are 2 databases wich share some tables with a BE database.
    From a form of database1 i want to start a function in database2. What i'm trying to do is set a value in a BE table. This value i use in a control in database2.
    When the value changes in database2 i want to trigger an event that execute that function. But when the value changes there is no event like AfterUpdate of this control that will be called.
    I taught that maby there is a possibility when the control that is written with a value from database 1 some event can be triggered?
    Probebly there is a more simple solution for this problem but this is how i want to fix this.

    Thanks for your help so far.

    Regards.

  14. #14
    Anna987 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    22
    Hello Minty,

    I'm not familiar with data macro. I find something on Youtube.
    I'll try it.

    Thanks.

  15. #15
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,934
    This value i use in a control in database2.
    for this to work, you (not another user) would have the have database2 open from within database1(and to be clear - you mean a front end, not a database which is the back end) and the relevant form open as well to be able to reference the control.

    All depends what your function is supposed to do but perhaps a data macro is the way to go....

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Changing value of bound field on event
    By Ganymede in forum Programming
    Replies: 5
    Last Post: 02-17-2016, 12:27 PM
  2. Trigger event with button click
    By AMAS in forum Forms
    Replies: 8
    Last Post: 06-07-2012, 09:42 AM
  3. event to trigger after new record
    By richlyn in forum Access
    Replies: 1
    Last Post: 03-02-2012, 10:26 AM
  4. Changing value of a field after an event.
    By mikethebass in forum Access
    Replies: 1
    Last Post: 06-16-2010, 04:42 PM
  5. Trigger subform event
    By tuna in forum Forms
    Replies: 0
    Last Post: 05-09-2010, 06:29 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