OnActivate when changing RecordSource

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • G Gerard

    #1

    OnActivate when changing RecordSource

    Hello

    I have noticed that whenever I set a form's RecordSource property
    in code it launches the form's OnActivate event.

    In one of my application I set a form's RecordSource to zero lenght string
    during the form's OnClose event

    Private Sub Form_Close()

    Me!RecordSource = ""

    End Sub

    On some computers setting the RecordSource during the OnClose event
    calls the OnActivate event of that form and causes errors since some of the
    code in the
    OnActivate refers to controls and subforms that are now closed.

    Any thought on this?

    Why is it not happening on all computers?


    Thanks
    G Gerard


  • Allen Browne

    #2
    Re: OnActivate when changing RecordSource

    Did you have a reason for setting the form's RecordSource in its Close
    event? Since the form is closing anyway, it does not seem like a useful
    thing to do, and yes, it can have undesirable side effects.

    Perhaps you are trying to avoid the situation where users are changing to
    design view and saving the RecordSource so it loads wrongly next time? If
    so, perhaps you could use code in the Open event of the form to initialize
    the form correctly instead of trying to reset it in Form_Close.

    A nasty side effect of setting the form's RecordSource is that it becomes
    unbound. Then every bound control is going to generate an error (or perhaps
    a parameter request.) You really don't want to do that! To avoid that, you
    could set the RecordSource so it has all fields but no records, e.g.:
    SELECT * FROM Table1 WHERE (False);
    I sometimes do that in Form_Open, but it still makes no sense to me in
    Form_Close.

    --
    Allen Browne - Microsoft MVP. Perth, Western Australia
    Tips for Access users - http://allenbrowne.com/tips.html
    Reply to group, rather than allenbrowne at mvps dot org.

    "G Gerard" <ggerard@nbnet. nb.cawrote in message
    news:9cRnh.4135 9$cz.608164@urs a-nb00s0.nbnet.nb .ca...
    Hello
    >
    I have noticed that whenever I set a form's RecordSource property
    in code it launches the form's OnActivate event.
    >
    In one of my application I set a form's RecordSource to zero lenght string
    during the form's OnClose event
    >
    Private Sub Form_Close()
    >
    Me!RecordSource = ""
    >
    End Sub
    >
    On some computers setting the RecordSource during the OnClose event
    calls the OnActivate event of that form and causes errors since some of
    the code in the
    OnActivate refers to controls and subforms that are now closed.
    >
    Any thought on this?
    >
    Why is it not happening on all computers?
    >
    >
    Thanks
    G Gerard

    Comment

    • G Gerard

      #3
      Re: OnActivate when changing RecordSource

      Hello Allen

      Thank you for your reply

      The reason I am setting RecordSource during the OnClose event
      is so I can delete the temporary table I have created (in another mdb)
      during the OnOpen event of the form to which the form is then bound.

      It’s a long explanation why I’m doing this but in short it’s to give the
      user the option of saving or not saving the changes made when closing the
      form
      while trying to avoid bloating of my main mdb on a multi user application.
      (with my knowledge of Access that’s the best way I have managed to do this)

      I didn’t think that unbounding the form during the OnClose would create any
      problem since at this point the records from the temporary table have been
      copied to a main table and the form is an instance.

      I will change the RecordSource to (SELECT * FROM Table1 WHERE (False);)
      instead of zero length string; it makes a lot more sense.

      Thanks
      G Gerard



      "Allen Browne" <AllenBrowne@Se eSig.Invalidwro te in message
      news:45a08b3b$0 $22052$5a62ac22 @per-qv1-newsreader-01.iinet.net.au ...
      Did you have a reason for setting the form's RecordSource in its Close
      event? Since the form is closing anyway, it does not seem like a useful
      thing to do, and yes, it can have undesirable side effects.
      >
      Perhaps you are trying to avoid the situation where users are changing to
      design view and saving the RecordSource so it loads wrongly next time? If
      so, perhaps you could use code in the Open event of the form to initialize
      the form correctly instead of trying to reset it in Form_Close.
      >
      A nasty side effect of setting the form's RecordSource is that it becomes
      unbound. Then every bound control is going to generate an error (or
      perhaps a parameter request.) You really don't want to do that! To avoid
      that, you could set the RecordSource so it has all fields but no records,
      e.g.:
      SELECT * FROM Table1 WHERE (False);
      I sometimes do that in Form_Open, but it still makes no sense to me in
      Form_Close.
      >
      --
      Allen Browne - Microsoft MVP. Perth, Western Australia
      Tips for Access users - http://allenbrowne.com/tips.html
      Reply to group, rather than allenbrowne at mvps dot org.
      >
      "G Gerard" <ggerard@nbnet. nb.cawrote in message
      news:9cRnh.4135 9$cz.608164@urs a-nb00s0.nbnet.nb .ca...
      >Hello
      >>
      >I have noticed that whenever I set a form's RecordSource property
      >in code it launches the form's OnActivate event.
      >>
      >In one of my application I set a form's RecordSource to zero lenght
      >string
      >during the form's OnClose event
      >>
      >Private Sub Form_Close()
      >>
      > Me!RecordSource = ""
      >>
      >End Sub
      >>
      >On some computers setting the RecordSource during the OnClose event
      >calls the OnActivate event of that form and causes errors since some of
      >the code in the
      >OnActivate refers to controls and subforms that are now closed.
      >>
      >Any thought on this?
      >>
      >Why is it not happening on all computers?
      >>
      >>
      >Thanks
      >G Gerard
      >

      Comment

      Working...