Form_OnLoad event


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Form_OnLoad event

  1. #1
    Marshal Guest

    Form_OnLoad event


    Dear Deborah,

    Everytime I try to connect or refer to a database from the Form_OnLoad event,
    and error occured saying "Object variable or With block variable not defined".
    This does not happen if paste the same code into Form_Activate event.

    Why does this happen? What is the correct way to go about this? What should
    I do to connect to a database when a Form is opened?

    Thank you,
    Marshal
    Share on Google+

  2. #2
    Rob Willis Guest

    Re: Form_OnLoad event


    Marshal...

    Please post the code so we can see exactly what you are trying to do...

    That said... are you using bound controls? I'm guessing that maybe you are
    and that you have set the databasename and/or recordsource properties on
    the actual data control.

    Thus, the data control isn't initialized during Form_Load, it is only initialized
    after the form has loaded which would explian why you can access the data
    in the activate event. If this is the case you could simply set those properties
    of the data control in the form load event (and be sure to refresh the data
    control) before you attempt to access the data.

    So... did I guess right?

    Good Luck,

    Rob Willis


    "Marshal" <meyung@tm.net.my> wrote:
    >
    >Dear Deborah,
    >
    >Everytime I try to connect or refer to a database from the Form_OnLoad event,
    >and error occured saying "Object variable or With block variable not defined".
    >This does not happen if paste the same code into Form_Activate event.
    >
    >Why does this happen? What is the correct way to go about this? What should
    >I do to connect to a database when a Form is opened?
    >
    >Thank you,
    >Marshal


    Share on Google+

  3. #3
    Phil Weber Guest

    Re: Form_OnLoad event

    > The data control isn't initialized during Form_Load, it is only
    > initialized after the form has loaded, which would explain why
    > you can access the data in the activate event. If this is the case
    > you could simply set those properties of the data control in the
    > Form_Load event (and be sure to refresh the data control)
    > before you attempt to access the data.


    Rob: Actually, if the DatabaseName and RecordSource properties are set at
    design time, all that's necessary in the Form_Load event is a call to the
    ..Refresh method. It's a good idea, however, *not* to hard-code the
    DatabaseName property (or to clear it before compiling the app), so that the
    app can work with a database in any location without requiring a recompile.

    It's an even better idea not to use data controls, but that's a subject for
    another thread... ;-)
    ---
    Phil Weber


    Share on Google+

  4. #4
    Rob Willis Guest

    Re: Form_OnLoad event


    Phil...

    Right! And I agree... no data controls in my stuff. But if you look at
    the problem that he described... I'm thinking he is using a dc... maybe I'm
    wrong... wouldn't be the first time.

    Rob

    "Phil Weber" <pweber@teleport.com> wrote:
    > > The data control isn't initialized during Form_Load, it is only
    > > initialized after the form has loaded, which would explain why
    > > you can access the data in the activate event. If this is the case
    > > you could simply set those properties of the data control in the
    > > Form_Load event (and be sure to refresh the data control)
    > > before you attempt to access the data.

    >
    >Rob: Actually, if the DatabaseName and RecordSource properties are set at
    >design time, all that's necessary in the Form_Load event is a call to the
    >..Refresh method. It's a good idea, however, *not* to hard-code the
    >DatabaseName property (or to clear it before compiling the app), so that

    the
    >app can work with a database in any location without requiring a recompile.
    >
    >It's an even better idea not to use data controls, but that's a subject

    for
    >another thread... ;-)
    >---
    >Phil Weber
    >
    >


    Share on Google+

Similar Threads

  1. Event not received by host
    By Jeff Yeager in forum VB Classic
    Replies: 1
    Last Post: 01-26-2003, 04:15 AM
  2. How long before the next version??
    By _CAG in forum .NET
    Replies: 146
    Last Post: 08-12-2002, 10:40 PM
  3. Re: App Object (fixes)
    By Rob Teixeira in forum .NET
    Replies: 129
    Last Post: 06-06-2002, 05:23 AM
  4. REPOST-from VB.dotnet.technical
    By Sachin in forum VB Classic
    Replies: 8
    Last Post: 09-09-2001, 11:29 AM
  5. Com+ Event Again
    By Arger in forum VB Classic
    Replies: 0
    Last Post: 09-29-2000, 02:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center