Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    LokeshSundar is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    6

    form.activecontrol.oldvalue not working

    Hi Team,

    i am using Office 365 and i have Access working. I am trying to do audit for the form and i have the code to track changes and which is working for dropdown list but not the textbox. Below is the function which i am using to track changes and i get error on the "frm.ActiveControl.OldValue" line. but the same line working fine for dropdownlist but not for textbox. i have a dollar value for the textbox. this code was working fine before friday(27/9/2019). but post friday it is not working. This also works for string values but not for dollar values

    Function Trackchanges()
    Dim db As DAO.database
    Dim rs As DAO.Recordset
    Dim strSql As String
    Dim strCtl As String
    Dim strReason As String
    Dim Number As Double
    Dim frm As Form

    Dim ctl As Control


    Dim OldVal
    Dim NewVal


    Set frm = Forms!frm_Opportunity

    'strReason = InputBox("Reason For Changes")
    strCtl = frm.ActiveControl.Name
    strSql = "SELECT * FROM tbl_Audit;"

    Set db = CurrentDb()
    Set rs = db.OpenRecordset(strSql, dbOpenDynaset)
    'Debug.Print frm.ActiveControl.OldValue
    'OldVal = CStr(frm.ActiveControl.OldValue)

    If rs.RecordCount > 0 Then rs.MoveLast

    With rs
    .AddNew
    rs!RecNo = frm.txtOppNbr
    rs!FormName = frm.Name
    rs!CreatedByUserID = frm.UserIDCreated
    rs!ChangedByUserID = fOSUserName
    rs!UserName = frm.LastModifiedBy
    rs!ControlName = strCtl
    rs!DateChanged = Date
    rs!TimeChanged = Time()
    rs!PriorInfo = frm.ActiveControl.OldValue <------- Error is appearing here
    rs!NewInfo = frm.ActiveControl.Value
    'rs!CurrentUser = fOSUserName
    rs!Reason = strReason
    .Update
    End With
    Set db = Nothing
    Set rs = Nothing
    End Function

    Click image for larger version. 

Name:	4FA74E3B.PNG 
Views:	52 
Size:	4.5 KB 
ID:	39851
    Click image for larger version. 

Name:	586D7B00.PNG 
Views:	52 
Size:	2.9 KB 
ID:	39852
    These are the error message which i get when i run the database.

    Thanks & regards,
    Lokesh S

  2. #2
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    I'm guessing this is being called in the before update event ?
    If it did work and now it doesn't something has been changed. That's either data or a control name.

    What is the result of your debug statements, and is the control bound ? it won't work on a calculated control or unbound one from memory.
    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 ↓↓

  3. #3
    LokeshSundar is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    6
    This is a bound control which is called in before update statement, and no control name is changed and it was working till last friday. it is a calculated bound control which was working before.

  4. #4
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    I assume from your answer that it is calculated in the forms underlying query, rather than on the form ? If it is the latter it won't have a an oldvalue hence your error.

    What is the result of your debug statements that are commented out?
    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 ↓↓

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    1) please use code tags (# on forum menu bar) and indentation to make your code more readable.
    2)
    it is a calculated bound control
    That makes no sense. A bound control cannot have a calculation as its recordsource. As previously stated, a calculated control has no OldValue property, which is probably the reason for the error message. I'm going to have to ignore your claim that it was working before and yet nothing was changed because you cannot successfully reference a control property that does not exist one day only to have it fail another day. Something would have to be different, even if it was just the way that the code executed. Perhaps some other control (like a button) has the focus because this is a function and not a sub that's tied to a control event? No harm, but why make it a function if it's not going to return any value? One other comment if I may. If you're going to create a With block for rs, no point in repeating the object variable name for every field update.

    Lastly, Number is a reserved word and you should not use it for object names.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  7. #7
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    rs!PriorInfo = frm.ActiveControl.OldValue <------- Error is appearing here
    Is the control in fact Active? I'm familiar with Screen.ActiveControl but not frm.ActiveControl. Doesn't the control need focus to be active?

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Quote Originally Posted by moke123 View Post
    Is the control in fact Active? I'm familiar with Screen.ActiveControl but not frm.ActiveControl. Doesn't the control need focus to be active?
    .ActiveControl is a property of a form yet the Micro$oft documentation uses the Screen object in conjunction with it, not the form. One of the more confusing explanations by M$
    https://docs.microsoft.com/en-us/off....activecontrol

    Oddly enough, Forms!formName.ActiveControl works in the immediate window but won't compile in code

  9. #9
    LokeshSundar is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    6
    Hi,

    I have tried with the
    Code:
    screen.activecontrol.oldvalue
    and
    Code:
    form.activecontrol.oldvalue
    and both are not working. i have retrived the database when it was working fine and it is same with that database as well. Any Help would be helpfull.
    Code:
    Function TrackChanges()
    Dim db As DAO.database
    Dim rs As DAO.Recordset
    'Dim rs As ADODB.Recordset
    
    Dim strSql As String
    Dim strCtl As String
    Dim strReason As String
    Dim Number As Double
    Dim frm As Form_frm_Opportunity
    
    Set frm = Forms!frm_Opportunity
    
    'strReason = InputBox("Reason For Changes")
    strCtl = frm.ActiveControl.Name
    strSql = "SELECT * FROM tbl_Audit"
    
    
    
    'Set db = CurrentDb()
    Set rs = CurrentDb.OpenRecordset("tbl_Audit")
    
    
    If rs.RecordCount > 0 Then rs.MoveLast
    
    With rs
    .AddNew
    rs!RecNo = frm.txtOppNbr
    rs!FormName = frm.Name
    rs!CreatedByUserID = frm.UserIDCreated
    rs!ChangedByUserID = fOSUserName
    rs!UserName = frm.LastModifiedBy
    rs!ControlName = strCtl
    rs!DateChanged = Date
    rs!TimeChanged = Time()
    rs!PriorInfo = Screen.ActiveControl.OldValue
    rs!NewInfo = Screen.ActiveControl.Value
    rs!Reason = strReason
    .Update
    End With
    
    Set db = Nothing
    Set rs = Nothing
    End Function

  10. #10
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    I think you will have to post a compacted and zipped copy of your db for analysis. Last ditch effort here - you could check for missing or broken references. I also see that one of the messages seems to be coming from another application - Opexb Pipeline? If it is something that we need in order to test your code, then posting the db won't help.

  11. #11
    LokeshSundar is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    6
    i was unable to update the database here so i am pasing the link for the database saved in the onedrive.
    https://1drv.ms/u/s!ArDY-GvljhEQhHrv...D5H4p?e=wR1O1h

  12. #12
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Quote Originally Posted by LokeshSundar View Post
    i have retrived the database when it was working fine and it is same with that database as well. Any Help would be helpfull.
    This would tell me that either it didn't actually really work, or something in your backend data structure has changed to stop it working.

    If an old unchanged version isn't working one of the two scenarios above must be the cause,or some external update has stopped it functioning.
    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 ↓↓

  13. #13
    LokeshSundar is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    6
    I have not changed any code or properties of the form or in the module. But how can a error occur on Office update.

  14. #14
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Quote Originally Posted by LokeshSundar View Post
    I have not changed any code or properties of the form or in the module. But how can a error occur on Office update.
    Unfortunately frequently if you have a read on various sites including here.
    I'm afraid I can't open your database -I'm on 2016 and it's complaining I need a newer version to open yours.

    I'm not convinced about your description of a calculated bound control either. What is it's control source?
    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 ↓↓

  15. #15
    LokeshSundar is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    6
    Control source is a query, which is connected to a table. you can hold shift and click the database it will open in the design mode

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

Similar Threads

  1. Replies: 9
    Last Post: 09-16-2014, 03:56 PM
  2. Subform Compare Value to Oldvalue
    By CementCarver in forum Programming
    Replies: 4
    Last Post: 09-12-2013, 03:19 PM
  3. Comparing New and Oldvalue in Subform Controls
    By CementCarver in forum Programming
    Replies: 3
    Last Post: 06-25-2013, 07:07 PM
  4. Need to stop update on drop-down. Need to keep OldValue
    By LindaRuble in forum Programming
    Replies: 1
    Last Post: 04-14-2013, 12:05 PM
  5. ActiveControl form Events - VBA
    By Epidural in forum Forms
    Replies: 5
    Last Post: 05-22-2012, 10:44 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