Results 1 to 5 of 5
  1. #1
    Pawtang's Avatar
    Pawtang is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    91

    Creating Events in VBA versus from Properties of form


    When I create a control_KeyDown(parameters) event directly in the VBA module for a form, it does not trigger. If I create it through the event creator on the properties sheet of the form, it does work. Is Access doing something in the background that associates the name of this function with an event only when you make it using Properties, but these function names don't do it alone? I am trying to create event controls for a non-trivial amount of text boxes, so its tedious to do it through the properties form, especially if I want to change the event that triggers it.

    For context, my general goal is to set up a continuous form so that the Up and Down arrow keys take you to the same field on the next or previous record, for faster data entry and less reliance on the mouse.

  2. #2
    Pawtang's Avatar
    Pawtang is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    91
    So, it looks like the developers of Access thought of this too! There's an option in "Client Settings" for continuous form navigation, you can choose up and down arrows.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    I stopped creating events from the vbe long ago because the odd one here and there failed to "connect".
    If you select all of the involved controls in design view you can apply the same user defined function for any event. However you often need a parameter to identify which control called it. Sometimes it can be as simple as relying on Screen.Active control. Other times you'd need to ID the control somehow, which I've done by individually providing a string as a parameter in the function call. So while I can assign 50 controls the same function for an event all at once, I have to go back and put e.g. txtCust as a parameter, or individually add a tag value and use that in code instead. It might not help you and it might seem like the same amount of work but I can tell you it beats creating 50 events, which is especially good in the event you ever have to modify the event. Better to modify one instead.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    That is normal behavior since as far as Access 97 as I recall. You can select all text boxes and enter the name of a macro that calls a public function with your code. For your current project have you considered turning on the KeyPreview property of the form itself to Yes then use the form's Keypress event for your navigation.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    If I’m correctly reading what you are doing
    - just writing the code, you still need to ‘connect it’ to the relevant control event I.e. write ‘event procedure’ for the relevant event property

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

Similar Threads

  1. Replies: 9
    Last Post: 03-30-2021, 03:13 PM
  2. Replies: 11
    Last Post: 05-31-2019, 09:03 AM
  3. Creating a database to track sports events and children
    By swellybro in forum Database Design
    Replies: 1
    Last Post: 09-29-2017, 04:04 PM
  4. recordset versus bound form
    By vicsaccess in forum Programming
    Replies: 4
    Last Post: 01-03-2016, 06:31 PM
  5. Fields show differently in table versus form.
    By zero3ree in forum Access
    Replies: 1
    Last Post: 08-01-2012, 03: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