Results 1 to 15 of 15
  1. #1
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76

    Module basics

    I'm not understanding Access Modules.


    A simple version of the question;
    I want global code that does not allow a form to be edited.
    I created a module:


    Public Function Permissions()
    Form.AllowEdits = False
    End Function




    then in a forms onCurrent event I wrote
    Private Sub Form_Current()
    Call UserPermissions
    End Sub


    Hopefully someone out there can help me get started. thanks!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try something like:
    Code:
    Public Function Permissions(InForm As String)
     Forms(InForm).AllowEdits = False
     End Function
    
    
    
    
     then in a forms onCurrent event I wrote
     Private Sub Form_Current()
    Call Permissions(Me.Name)
     End Sub
    Warning...NOT TESTED...

  3. #3
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    Thanks for the response, but the code does not work.
    There are no compile errors or messages.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Alright, does this form have a RecordSource? If so then try:
    Code:
    Private Sub Form_Current()
    MsgBox "Before - AllowEdits = " & Me.AllowEdits
    Call Permissions(Me.Name)
    MsgBox "After - AllowEdits = " & Me.AllowEdits
     End Sub
    If not then you will probably not get a Current Event and need to use OnLoad instead.

  5. #5
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    This is not working either. I used the code in both the OnLoad and the OnCurrent event.
    same as before, no compile errors or messages.
    This is kind of frustrating, it seems like a simple thing, but I must be overlooking something in my message that is not allowing the problem to move forward.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you set your Trusted Locations yet? You should at least get the MsgBox's.

  7. #7
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    Trusted locations are all good.
    Strange thing, when I use the code you provided nothing happened, so I added "msgBox ("onCurrent") to the top line of the code and nothing. I then commented out your code and when I launched the form I got my message "onCurrent".
    Same thing happened with Onload.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Something weird is going on. Does this form have a RecordSource?

  9. #9
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    Yes, the form does have a record source.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Then you'll get a Current Event. Can you zip and post the db? It sound like it is still in test. Remove any sensitive data if not.

  11. #11
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    falseEdit.zip
    I created a new db that just does what I want it to do; have a module that allows the edit record property to be False and a form that calls this module.
    Interestingly enough after creating the new db the code does not compile. I sure hope what I sent is clear and that you can help.
    Thanks.

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The Module name cannot be the same as a Procedure it contains.

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I named my module basCode. It now compiles and works as I expected.

  14. #14
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    Thank you for the fix and your patients.
    it works as expected.

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Excellent! Glad we could help.

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

Similar Threads

  1. Basics ...
    By Dega in forum Access
    Replies: 4
    Last Post: 05-08-2012, 11:48 AM
  2. class module vs regular module
    By Madmax in forum Modules
    Replies: 1
    Last Post: 05-01-2012, 03:44 PM
  3. Replies: 2
    Last Post: 03-29-2012, 02:19 PM
  4. Run a Module
    By mchadwick in forum Modules
    Replies: 7
    Last Post: 09-02-2011, 09:24 AM
  5. Replies: 4
    Last Post: 05-16-2011, 04:58 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