Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2003
    Posts
    311

    Unanswered: Protecting my vba from others?

    i just noted that an error ocured in my code and some one who i didnt think would be able to have access to my module could just go in there and debug it. Note i don't have any errror handling ( dont know how to do in VBA ( allthough i know its simple)

    How can i keep others from acessing my vba code?

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    The quick and easy answer is to "compile" your db into either an mde or ade.

  3. #3
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    here's a hint on error trapping:

    Use the wizards to add a button to your form (Save or Close or something).

    Then, go look at the code behind the button - the wizaeds come in with basic error trapping.

  4. #4
    Join Date
    Nov 2003
    Location
    Sussex, England
    Posts
    404

    vba code

    if you put as the first line of code in any sub routine or function:

    On Error Resume next

    That may put your code into a pemrenant loop or even allow it to igonore an error - either way your code should not become visible:

    Another solution is:

    sub DoSomething()
    on error goto DoSomething_err

    docmd.clise

    exit sub
    DoSomething_err:

    select case err.number
    case 468
    resume next
    end select
    end sub

    This way the code can carry on its merry way (case 468 refers to the specific error the "docmd.clise" creates.


  5. #5
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    I see a couple of suggestions here. I'm going to weigh in with the Monkey's advice. Compile your project's code into an MDE.

    Even if you create error handling to simply exit your code whenever an error occurs, your code can still be viewed simply by looking at the VBA project window. It can also be interrupted with <ctrl-break>.

    If you're going to be writing code for applications that others will use, you may want to look into error trapping. You'd be surprised how many people become astonished when your app actually tells them what they did wrong.
    All code ADO/ADOX unless otherwise specified.
    Mike.

  6. #6
    Join Date
    Oct 2003
    Posts
    311

    How do i compile my CODE into a mde?

    How do i compile my CODE into a mde? how would this change the db in total? and for other users?

  7. #7
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile Re: Protecting my vba from others?

    Originally posted by mikezcg
    i just noted that an error ocured in my code and some one who i didnt think would be able to have access to my module could just go in there and debug it. Note i don't have any errror handling ( dont know how to do in VBA ( allthough i know its simple)

    How can i keep others from acessing my vba code?
    Another thought is using the Tools/Properties menu and selecting protection from the code window. I think you have some options here to lock the project for viewing etc.

    I've honestly never used it but in later versions of Access I think that this is the only way to secure code aside from the MDE approach.

    Going on memory here so I hope I'm not too far off base.
    Gregg


    DAO, ADO, SQL, Automation and anything else I can pick up.

  8. #8
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    How do i compile my CODE into a mde? how would this change the db in total? and for other users?
    If you have > Access2000, you convert your db into Access 2002 format, and then choose Make MDE file, both under the Database Utilities menu.
    All code ADO/ADOX unless otherwise specified.
    Mike.

  9. #9
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    to quote:
    How do i compile my CODE into a mde? how would this change the db in total? and for other users?

    It's a menu option: Tools . Database Utilities . Make MDE

    You make the mde when you are done and ready to distribute.

    mde compiiles (and removes) all the code and changes to objects (forms, reports, etc.) are not allowed.

    You will need to set Startup Options, at the very least a startup form, before making mde - menu: Tools . Startup

    You keep your mdb around in case you need to make changes, but users get the mde.

    In an mde, if it hits an error, it simply closes the application, sometimes without notice, sometimes with an error message that often doesn't make sense.

    mde is the last thing you want to do.
    Error trapping is a good idea in the beginning.

    read this:
    http://www.microsoft.com/resources/d...us/65t3_4.mspx

    if the link didn't work, goto www.msdn.microsoft.com and search for "MDE" and select the link for "Helping Protect Source Code with an MDE or ADE File"

  10. #10
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231

    Re: Protecting my vba from others?

    Originally posted by mikezcg
    i just noted that an error ocured in my code and some one who i didnt think would be able to have access to my module could just go in there and debug it. Note i don't have any errror handling ( dont know how to do in VBA ( allthough i know its simple)

    How can i keep others from acessing my vba code?
    I see a lot of people have answered already, so i won't reiterate what they've said. Just wanted to give you a kick-start on error trapping. error handling is ALWAYS a good idea from the beginning (to reiterate what someone else already said ). here's the deal: at the very beginning of your function or sub, put the line on error goto errorhandler
    Code:
    Private Sub Whatever()
    On Error GoTo errorhandler
      .'code goes in here
      .'code goes in here
      .
      Exit Sub  'this is necessary so you don't plod into the errorhandler part 
    
    errorhandler:
      MsgBox err.number & " - " err.desc
      Resume Next:
    
    End Sub
    what all this would do is, in the event of an error, it would put up a message box with the error number followed by a dsah and the error description. so it would look like "3021 - Recordset is at EOF".
    the "Resume Next:" tells the program to continue from the next line of code after where it left off. a simple "Resume:" without the "Next" will go back and try the same line of code again. if you wanted the program to just exit the sub after displaying the error message, leave off the resume part. it will go to the next line of code, which is "End Sub"
    this makes for effective debugging, in that you could put in the errorhandler
    Code:
    errorhandler:
       If err.number = 3058  Then    'string contains a null value      
           strTemp = strTemp & ""
           Resume:
       End If
    
       Msgbox err.number & " - " err.description
    
    End Sub
    that would allow you to change the string that had a null value to an empty string and continue where you left off. any other error that was thrown would alert you with the messagebox and then quit the sub. hope that helps a little.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •