Results 1 to 9 of 9
  1. #1
    BluePlastic is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    5

    USe CreateObject to create a new form

    Hiya



    I have a function that accepts a string variable that is the name of a form (e.g. "frmMain") and I need to create a new instance of the form, which I can't use the New word to do as it doesn't accept a string variable - so I was expecting to use CreateObject:

    Sub subA (pstrFrmName as string)
    Set gfrmAny = CreateObject("MyDB.form_" & pstrFrmName)
    End Sub

    But I receive error 'ActiveX component can't create object'

    Any ideas please?!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Google: Access vba multiple instances of form

    Here is one
    http://bytes.com/topic/access/answer...form-ms-access
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    BluePlastic is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    5
    No that just indicates how to open multile firms, not 'accepts a string variable that is the name of a form'.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I believe the code uses a loop to open 4 instances of the same form. I thought it could be adapted to open only the one duplicate instance you want. But I understand now what you mean by New does not accept variable. However, all examples I can find show use of New. Even Allen Browne used it http://allenbrowne.com/ser-35.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    BluePlastic is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    5
    Indeed. I think the answer is that is is not possible.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Maybe. But you know the names of all forms that could possibly want to do this with, right? Build a case structure in procedure and use the variable input to pick the correct case which has the form name hard coded with the New. It means repeating the New line in each case but only have to do it once for each form and then it's done.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    BluePlastic is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    5
    The case structure is what I currently have (120 forms so far) and am trying to replace :-)

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Why would you need to have multiple instances of virtually every form in project? Oh well, it is built and works? Sounds like you will have to stick with it.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    BluePlastic is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    5
    It's been running for 15 years.

    I make no assumptions for power users about what they should and shouldn't be able to open multiple copies of - I give them full flexibility with not much overhead as it's all from a central function: I've done it for a few so I might as well implement it for the lot.

    This is investigative prep for a rewrite (and me trying to get a better grip on classes) - the 2GB file size limit is becoming a pain for 8 GB of data a month :-)

    Nearly every form can be opened in the context of a particular area of the business and the code deals with this filtering of the data to allow that via passing of variables.

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

Similar Threads

  1. Replies: 1
    Last Post: 12-11-2011, 11:48 AM
  2. Which data type for createobject?
    By BRV in forum Programming
    Replies: 6
    Last Post: 11-11-2011, 07:34 AM
  3. If Then CreateObject
    By cg1465 in forum Forms
    Replies: 3
    Last Post: 09-28-2010, 07:06 PM
  4. Replies: 1
    Last Post: 03-02-2009, 11:54 AM
  5. How do I specify a version of Word using CreateObject?
    By TrevorOlding in forum Programming
    Replies: 1
    Last Post: 03-17-2006, 12:15 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