Results 1 to 8 of 8
  1. #1
    yasser hamdy is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    5

    creatobject vs getobject

    Hope that you are all OK .
    Sorry to bothering you , but I have a question if you please .
    What is the difference between Createobject and Getobject in vba and when can I use each ?

    Thank you for your time

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Essentially one will create a new instance of the Object, and the other will get a existing instance if it exists.

    https://vbaoverall.com/getobject-vs-createobject-vba/
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Just to add to Minty's comments, GetObject code is usually run first to use an existence instance of e.g. Outlook or Excel if it exists. If not, that triggers error 429 and CreateObject is then run to open a new instance. See https://docs.microsoft.com/en-us/off...bject-behavior
    Last edited by isladogs; 03-13-2021 at 11:28 AM. Reason: Corrected link
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    yasser hamdy is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    5
    Thank you for your replay . .
    but really i can not know what is the mean of "instance" . .
    mean that there is a Ms word installed in the computer ?
    or
    mean that there is an open word document ?
    i try both with Getobject but i got error . . not 429 . .
    and what is the relation of adding Ms word reference with all that . .

  5. #5
    yasser hamdy is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    5
    Quote Originally Posted by isladogs View Post
    Just to add to Minty's comments, GetObject code is usually run first to use an existence instance of e.g. Outlook or Excel if it exists. If not, that triggers error 429 and CreateObject is then run to open a new instance. See http://www.mendipdatasystems.co.uk/c...ace/4594365418
    Thank you for your replay . .
    but really i can not know what is the mean of "instance" . .
    mean that there is a Ms word installed in the computer ?
    or
    mean that there is an open word document ?
    i try both with Getobject but i got error . . not 429 . .
    and what is the relation of adding Ms word reference with all that . .

  6. #6
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Can you post the code where you are getting the error?
    Show any error numbers and descriptions.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Post 5 was moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Apologies. I posted a link to my website in error in post #3. I've now corrected that post.

    GetObject is used to automate working with an open Office application such as Excel.
    if you use CreateObject instead that would create two open 'instances' of Excel which is usually undesirable..

    So the idea is to first test whether e.g. Excel is open using GetObject. If not, error 429 provide a prompt and CreateObject is then used.
    Re-check the earlier links in posts 2 & 3 for how this should be coded
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Replies: 3
    Last Post: 02-23-2012, 07:16 PM
  2. VBA - Using GetObject function - get error.
    By jsbotts in forum Programming
    Replies: 7
    Last Post: 10-10-2011, 07:51 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
  •  
Other Forums: Microsoft Office Forums