Results 1 to 7 of 7
  1. #1
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265

    How do you use an event property for a form?

    I understand how to use the events of a form. In the property sheet, click the Events tab, select the event you want, click the builder button, and type your code into the sub routine that appears.



    But let's say you want to use a form property that is associated with an event, such as:

    Code:
    Me.BeforeInsert
    Where would you type this code in? From what I gather, it would be

    Code:
    Me.BeforeInsert = procedureName
    I am trying to find out:

    1. Where would you actually type this code? Please outline the steps.
    2. Please show an example where a macro is invoked.
    3. Please show an example where an event procedure is invoked.

  2. #2
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187

    Re: How do you use an event property for a form?

    In the visual basic editor.. you can access all form events there

  3. #3
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by BRZ-Ryan View Post
    In the visual basic editor.. you can access all form events there
    Ok now I "see it." In Excel VBA you can type code in a module, and when doing that, you can change the property for an object, such as a worksheet object. In Access VBA I see that you can also add a module there as well, and then simply refer to the object in question and change its properties. Now I get it.

    Thank you. I'm still trying to understand the "big picture" but now I think I see a lot more of it.

  4. #4
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by BRZ-Ryan View Post
    In the visual basic editor.. you can access all form events there
    I don't see any icons to wrap tags around code.


    What about this? I have this code in Module 1. I get an error saying "can't find object 'message.' " I am trying to say when I start typing a new record into the form called "Gymnast" the message box in the second procedure should be triggered.

    Sub testingForms()
    Forms!Gymnast.BeforeInsert = "[message]"
    End Sub

    Sub message()
    MsgBox "This is a test of the BeforeInsert property"
    End Sub

    How would I get this to work? Would I have to put the cursor in the first procedure, then press F5 in the VB Editor, then go back to my form and test it by adding a new record?

    Or would I just go right back to the form and the code would automatically be invoked? In short, what do I have to do to trigger this code.

  5. #5
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187

    Re: How do you use an event property for a form?

    VBA doesn't work with code tags. You place code in the event where you want it to fire.. Play around with form_current, and try the condition :

    if me.newrecord then
    Msgbox "hi"
    End if

  6. #6
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by BRZ-Ryan View Post
    VBA doesn't work with code tags.
    When I said tags, I was referring to tags to put around my code example in my post above.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Go to the Advanced post editor. Click button below the quick reply post editor.

    Can type them once you become familiar with them.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 5
    Last Post: 07-05-2013, 06:08 AM
  2. RecordSource Property of a form
    By mkc80 in forum Access
    Replies: 4
    Last Post: 08-11-2012, 05:43 PM
  3. Replies: 3
    Last Post: 07-20-2012, 11:41 AM
  4. Replies: 0
    Last Post: 03-30-2012, 12:24 PM
  5. Change form property with VBA
    By jmk909er in forum Forms
    Replies: 1
    Last Post: 10-20-2010, 08:57 AM

Tags for this Thread

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