Results 1 to 6 of 6
  1. #1
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114

    How to suppress Current event code?

    I have a 1 to many relationship set up in the usual way with a subform embedded in the main form and an unbound combobox in the mainform which serves as the masterlink for the subform control - ie. choosing an entry in this combobox, whose afterupdate event has a requery of the subform, causes the subform to display the records expected from the relationship.



    However, the subform was initially developed as an independent form, and there's code in the current event that I want executed only through user manipulation of onscreen records, not when a requery fires the current event.

    Is it possible to selectively suppress the current event when fired from a requery? How would one go about this, or am I offbase in how I've set this up? (I know I can do it by setting a filter from the unbound cbobox, but I've read that going the query route is much more efficient.)

    Thx -Ron

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    You question is quite vague in one sense in that there is no context. Can you tell us about the database and show a jpg of the tables and relationships?

    Also, there may be options to accomplish what you want to do, if readers knew more about the set up.
    I'm not following how the unbound combo on main serves as the masterlink??? Typically, the link would be done via the key on the 1 side and the FK on the many side in the subform.

    Perhaps you could show a couple of screen captures and/or some code to clarify. I'm not trying to be difficult - I'm just not following the unbound combo as a masterlink???

  3. #3
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    You can, but you will need to know exactly when you want to suppress the Event, including exactly what values to check. If you know that, then you can just wrap the Form's On Current Event in an If statement checking for your conditions.

  4. #4
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Thanks for the responses. I've partially fixed the problem I was having, and it obviates the need to deal with the code in my current event, at least for moment. (I still have an issue, and I think it relates to not having an unfiltered recordsource set for the subform when it loads. As you know, a subform loads before its main form does.)

    Orange - I was purposely vague because I knew there were issues in my code and I was simply trying to explore debugging techniques. From my reading there's no simple way to tell which control has triggered an event, and with my inexperience, I'm not clear yet on all the ways an event, Current in particular, can be triggered. In my case, it was being triggered by a requery of the subform set on a new record - hence triggering current code I didn't want - instead of the filtered recordsource I expected which should not create a new record when opened. I've since fixed that (I think). To respond to your comment on the typical situation, the linkmaster in my subform control is set to (column 1 of) an unbound combo box in the main form, and that value *is* the primary key of the "1 table" and does have a foreign key counterpart in the subform recordsource (a query on the "many" table). From my reading, this is a common technique when you don't want to actually display main form records. And I do realize, I don't even need to have the subform embedded in a main form to accomplish the same thing, but I'm trying to establish flexibility for future expansion.

    Rawb - understood, and thanks. Problem is a noob doesn't necessarily know which "when's" trigger the event in the first place.

    -Ron

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Here are a couple of links.

    You could have a preliminary form with the combo, make a selection (Company), and then open the Main and Subform with an OpenArgs argument. I know Martin green has tutorials on this.
    Here's his Access link http://www.fontstuff.com/access/index.htm
    Here's one on Dynamic Reports, but the concept could dynamic forms if you want.
    http://www.fontstuff.com/access/acctut19.htm

    For some of the best debugging techniques see Chip Pearson's stuff at
    http://www.cpearson.com/excel/DebuggingVBA.aspx

    Events and Objects
    http://office.microsoft.com/en-us/ac...005186761.aspx

    good luck,

  6. #6
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Thanks Orange, I'm bookmarking those sites. Just glancing at the Martin Greene example, though, note that he's using the combo box to define and activate the filter property, not to modify a query used as a recordsource. I've shown myself I can do the former, following the *first* technique in this ref: http://allenbrowne.com/ser-28.html . But now I want to use the *second* technique there, because I've read it's more efficient. Trouble is I thought I was smart enough to work it out on my own rather than more closely follow his advice. Hah!

    Thx again for the refs. Looks like some good reading. -Ron

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

Similar Threads

  1. Information message on current event
    By justauser in forum Forms
    Replies: 5
    Last Post: 02-07-2012, 12:15 PM
  2. Replies: 5
    Last Post: 10-26-2011, 02:59 PM
  3. Replies: 7
    Last Post: 01-19-2011, 10:39 AM
  4. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 AM
  5. How to put code in form event.
    By rogdawg in forum Forms
    Replies: 4
    Last Post: 08-06-2010, 03:38 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