Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    sub intentianally not defined

    I have a condition where the module that a sub would have been located in will INTENTIONALLY be deleted (and by default the sub.)
    Elsewhere in the project there is a line of code that would call the sub - if it still existed (It's OK when it does not, that part of the plan...)

    Thought this below code would get me around an error call when it no longer does (and i thought it had), but as a clean-up... this seems to not be the case(?) ()maybe it never was?): I do get the error: "sub... not defined"

    Am i missing something?

    Code:
        On Error Resume Next
            Call ClearNothing
        On Error GoTo 0
    with appreciation and thnx in advance,


    m.

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    this is a compilation error, not a runtime error - unless you have precompiled your code access will 'compile as it goes'. So the called function needs to exist.

    No idea why you are deleting a module, but if you are, you need to delete the calling code as well.

    If you compile then delete the module or make any change that impacts compilation for that matter, the code becomes uncompiled so you are back to square one.

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    You could create a new function that always exists to call ClearNothing. If ClearNothing does not exist, you can trap it in the new function to do nothing.

    Edit: I tried that and you can't trap the error. Instead of trapping the error the new function would need to scan for the module name as below.

    Code:
    Option Compare Database
    Option Explicit
    
    
    Public Function Wrapper()
        Dim i As Variant
        ' iterate thru modules
        For Each i In CurrentProject.AllModules
            If i.Name = "MyTransientModule" Then
                ' module exists, so call function in that module
                Call ClearNothing
                Exit For
            End If
        Next i
    End Function

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    interesting solution - just tried it and I get the 'sub or function not defined 'error when either trying to compile or executing without compiling

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Have you explored Microsoft Visual Basic For Applications Extensibility

    http://www.cpearson.com/excel/vbe.aspx
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Mark,
    Can you please describe the business issue that is addressed with your proposed set up? Perhaps provide an example or2 to clarify things.
    I don't understand the "plan".

  7. #7
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    the plan is a bit nefarious
    I work in a small niche industry, taught myself ACCESS / code / VBA, and wrote a continuously evolving project (on my own time) that is used extensively within our office (and could easily be extended industry-wide). I plan to retire soon. Sadly, the evolution of the project will come to a screeching halt

    On that first day that I am gone, I'd like the software to open with a splash "good-bye, it's been nice knowing you..." form (maybe with a bit of dark sarcasm -which i am know for). The image would hang around for 5-10sec +/- and then go away... never to be seen again (just like me!) After that happens, I would like all traces of that event to go away (the splash, not the code) (even though, trust me when i say, there is no one in the office with even the smallest bit of interest in writing code...)

    delete the form,
    delete the table (which contains date and time info -when to start using the form as the splash image),
    delete the module that contains the code to execute...


    (Each user has their own 'front-end')
    ___________________
    behind the main menu:
    Code:
            
        On Error Resume Next
            Call ClearNothing
        On Error GoTo 0
    ___________________
    in the code module
    Code:
     Sub ClearNothing()
        blnItsTime = DLookup("CloseDate", "tblNothing") < Now()
        If blnItsTime Then
            DoCmd.OpenForm "frmNothing" 'form is popup / modal / acDialog: code 'should' pause until the form is closed
            DoCmd.DeleteObject acForm, "frmNothing"
            DoCmd.DeleteObject acModule, "modNothing"
            DoCmd.DeleteObject acTable, "tblNothing"
        End If
    End Sub
    ___________________
    behind the form (popup, modal, acDialog)
    Code:
    Private Sub Form_Open(Cancel As Integer)
        Me.TimerInterval = 7500      '1000 = 1 second
    End Sub
    
    Private Sub Form_Timer()
        DoCmd.Close acForm, Me.Name
    End Sub

  8. #8
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    A sort of "this tape will self destruct in 15 seconds" moment then
    It's a bit of chicken and egg scenario when you start thinking it through though.

    Allow me to cogitate with a beer this evening and try to work something 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 ↓↓

  9. #9
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Quote Originally Posted by CJ_London View Post
    interesting solution - just tried it and I get the 'sub or function not defined 'error when either trying to compile or executing without compiling
    If you're referring to post #3, that's odd. No errors at all and it works perfectly as expected for me.

  10. #10
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    If you're referring to post #3,
    yes, just copy/pasted your code - I also tried removing option explicit and changed the error handling to Break on Unhandled Errors (I usually have it set to Break in Class Module) - could not get it to compile or run.

  11. #11
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Quote Originally Posted by CJ_London View Post
    yes, just copy/pasted your code - I also tried removing option explicit and changed the error handling to Break on Unhandled Errors (I usually have it set to Break in Class Module) - could not get it to compile or run.
    You are correct. My testing technique was faulty. Instead of deleting MyTransientModule, I changed its name. That simply left function ChangeNothing intact in a different module instead of destroying it.

  12. #12
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    "this tape will self destruct in 15 seconds"

    ... EXACTLY !

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    And could easily be used to delete valid code as well? if perhaps you were being sacked?
    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

  14. #14
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Quote Originally Posted by Welshgasman View Post
    And could easily be used to delete valid code as well? if perhaps you were being sacked?
    There's easier ways than this... #cynic#
    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
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    I worked at one place where a manager was not sacked, but was leaving as he was refused a pay rise.
    He chamged all the passwords on the VAX system, that they had to get VAX in to be able to use the system again.

    If you think about it, it would be pretty untraceable?

    Not saying that is actually the case here, else why say it's purpose, but still.....
    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

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

Similar Threads

  1. Replies: 4
    Last Post: 05-10-2021, 01:28 PM
  2. Compile error User-defined type not defined
    By Ashfaque in forum Modules
    Replies: 8
    Last Post: 03-03-2021, 03:37 AM
  3. Replies: 7
    Last Post: 01-10-2020, 04:50 PM
  4. Replies: 4
    Last Post: 10-16-2017, 09:09 AM
  5. Replies: 3
    Last Post: 11-12-2013, 04:13 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
  •  
Other Forums: Microsoft Office Forums