Results 1 to 5 of 5
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    Undo any control in a form

    I've got a logon form with three entry controls.
    There is also a timer to null out the controls if logon isn't completed.

    Here is the code from the Form_Timer procedure:

    Code:
    Private Sub Form_Timer()
      '** check if times has passed to accept, reset entries
      Dim FldNm
      Const nProc = "Form_Timer"
      Call sAddStatus(Me, lCntl, nProc, lCntl(2, 3), 1)
      If (Now - UserCdTm) * 86400 > lCntl(0, 10) Then
        ValidLo = False
        'If Me.ActiveControl.Name = "cbx_3_LangID" Then cbx_3_LangID.Undo   'this works but need all controls
        FldNm = Me.ActiveControl.Name
        'On Error Resume Next
        Me.Controls(FldNm).Controls(0).Undo   'RTE 2467
        On Error GoTo 0
        cmb_3_Accept.Enabled = False
        tbx_3_UserCd = Null
        tbx_3_Password = Null
        Me.TimerInterval = 0
        UserCdTm = Now
        tbx_3_UserCd.SetFocus
        'Tbxs_Status = fTranltLang(TempVars!LoLangID, "3_StatusWaitLogon", "H")
        Call sAddStatus(Me, lCntl, fTranltLang(TempVars!lolangid, "3_StatusWaitLogon", "H"), lCntl(2, 3))
     End If
    End Sub
    RTE : The expression you entered refers to an object that is closed or doesn't exist

    The line that does the .Undo for a specific control works.
    However, I need the .Undo to work for any control that is active.


    Maybe I have the syntax wrong on the line that is getting a RTE 2467?

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Code:
    Me.Controls(FldNm).Controls(0).Undo
    Not sure a label can be an active control, nor can a label be undone.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    @moke123, post #2
    I haven't yet figured out how the Controls(0) part works, or what it all means.
    I'm not trying to undo the label, just the combo box as in the line three above.
    (Or any textbox or control that has a bad entry that won't allow focus to move to another control while it has the bad entry.)
    Maybe there is a better way?

  4. #4
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    Since I copied that code and changed it, moke123's comment got me thinking.
    So, I removed the second .Controls(0), and guess what, it seems to work!
    If you know where in the documentation the .Controls(0) is covered, I would like to read up.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    A textbox can have a controls collection. There is only ever one member of the collection thus its position is zero (0). The only member of the collection is the attached label. If the label is not attached the collection has no members (or it doesn't exist at all, not sure which but it doesn't matter to me). Thus txtMyTextbox.Controls(0).Caption gets you the caption of the attached label.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 2
    Last Post: 08-06-2022, 12:02 PM
  2. control undo
    By markjkubicki in forum Programming
    Replies: 3
    Last Post: 08-18-2021, 12:43 AM
  3. Replies: 4
    Last Post: 11-24-2020, 03:41 PM
  4. Need Help: Form Undo Error
    By RichardAnderson in forum Forms
    Replies: 1
    Last Post: 10-10-2013, 12:41 PM
  5. Replies: 7
    Last Post: 07-15-2011, 08:14 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