Results 1 to 13 of 13

Thread: Error Set f = Form1 [HELP]

  1. #1

    Thread Starter
    Addicted Member *PsyKE1*'s Avatar
    Join Date
    Jun 2010
    Location
    Spain
    Posts
    243

    Question Error Set f = Form1 [HELP]

    Let's say I have this:
    Code:
    Dim f as Form
    Set f = New Form
    If there is no form named "Form1" will fail to create ...
    My question is:
    How I can declare sure there is an form with the same name in the project so I will not return an error?

    Thanks

  2. #2
    Addicted Member Programmation's Avatar
    Join Date
    Nov 2009
    Posts
    161

    Re: Error Set f = Form1 [HELP]

    I think u have to select which form will declared for F
    for example u have From named frmMain so your code will be:

    Code:
    Dim  F As Form
    Set F = New frmMain
    then u can do what u want for example make the caption of frmMain equal to caption of F,Like this:

    Code:
    F.Caption = "VBForums"
    frmMain.Caption = F.Caption
    hope that is what you want

    Regards.
    Last edited by Programmation; Sep 13th, 2010 at 04:29 PM.
    Just Do It!

  3. #3

    Thread Starter
    Addicted Member *PsyKE1*'s Avatar
    Join Date
    Jun 2010
    Location
    Spain
    Posts
    243

    Re: Error Set f = Form1 [HELP]

    Thanks but that was not what I wanted ...
    I will explain better:
    I have a function to create a new form ... then put this:
    vb Code:
    1. Dim f as Form
    2. Set f = New Form1
    But if the draft is not an exact form called "Form1" is not going to work ...
    How do I fix this?
    Do I explain myself?
    Thanks

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Error Set f = Form1 [HELP]

    Quote Originally Posted by *PsyKE1* View Post
    Let's say I have this:
    Code:
    Dim f as Form
    Set f = New Form
    If there is no form named "Form1" will fail to create ...
    My question is:
    How I can declare sure there is an form with the same name in the project so I will not return an error?

    Thanks
    Don't you know the names of the forms in your project?

  5. #5
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Error Set f = Form1 [HELP]

    Are you trying to create a form at RunTime?
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  6. #6

    Thread Starter
    Addicted Member *PsyKE1*'s Avatar
    Join Date
    Jun 2010
    Location
    Spain
    Posts
    243

    Re: Error Set f = Form1 [HELP]

    Are you trying to create a form at RunTime?
    Yes i do
    Don't you know the names of the forms in your project?
    of course!
    But I'm trying to make my function as generic as possible.
    Creeuna I want a copy of any form of my project.
    CallByName could help?

    Thanks

  7. #7

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Error Set f = Form1 [HELP]

    You can do the following but I don't know why you'd want to.

    Code:
    Public Sub CreateForm(frm As Object)
    
       frm.Show
        
    End Sub
    Usage:

    Code:
    CreateForm Form2 ' Where Form2 is an existing form in your project

  9. #9

    Thread Starter
    Addicted Member *PsyKE1*'s Avatar
    Join Date
    Jun 2010
    Location
    Spain
    Posts
    243

    Re: Error Set f = Form1 [HELP]

    Thanks, but it isnt that i found...
    I want to create a reply of any Form which is in my proyect, runtime...

    Really Thanks

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Error Set f = Form1 [HELP]

    In order to create a new instance of a form/object, you need to use the keyword NEW. And I don't think you can use a variable or reference as the form/object.
    Last edited by LaVolpe; Sep 14th, 2010 at 01:21 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Error Set f = Form1 [HELP]

    How about
    vb Code:
    1. Public Sub ShowForm(ByVal pstrFormName As String)
    2.     Dim MyForm As Form
    3.     Set MyForm = Forms.Add(pstrFormName)
    4.     MyForm.Show
    5. End Sub
    6.  
    7. Private Sub Command1_CLick()
    8. ShowForm "Form2"
    9. End Sub

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Error Set f = Form1 [HELP]

    Hack, crud! You beat me to it. I just re-discovered the same thing.

    For Psyke1. I still don't see the advantage of building a function/sub to create a new instance of a form. I have no idea what that sub/function will do with the created form, but if it adds controls, modifies form properties, I think this would be more intuitive (code-wise) and less involved
    Code:
    Dim f As Form
    Set f = New Form1
    ' now call a sub and pass f so that new controls can be added or properties changed
    But your project, your call. Don't forget to add error trapping in case the passed form name is not part of the project.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  13. #13
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,948

    Re: Error Set f = Form1 [HELP]

    You will be required to add in some sort of error checking process, that is built into your COM Project...
    Try making it look, like this:
    Code:
    On Error Goto ...........
    I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...

    |Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Love Shack | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University | Ambra Cheese |

    Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width