Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Join Date
    Apr 2008
    Posts
    189

    Question Unanswered: Problem to CreateControl in an open Form

    I have this VBA code in a Form called "Formulario1"

    Code:
    Private Sub b()
    DoCmd.OpenForm "Formulario1", acDesign
    Set ctlLabel = CreateControl("Formulario1", acLabel, , , Now)
    DoCmd.OpenForm "Formulario1", acNormal
    End Sub
    What I'm trying to do is create a acLabel inside the Form that has a button thar runs b

    Code:
    Private Sub Comando0_Click()
    b
    End Sub
    For some reason tells me this:

    Se ha producido el error '29054' en tiempo de ejecución.

    Microsoft Office Access no puede agregar, cambiar el nombre o elimiar los controles seleccionados.
    Or in English:
    Microsoft Access can't add, rename, or delete the control(s) you requested.
    Any ideas?

    I have the form "Formulario1" open, also that form is the one who has the button "Comando0".

    Ideas?
    Thanks!
    Last edited by pepemosca; 05-06-08 at 18:03.

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Why do you need to do it? Why not make the label manually and just change the Visible property?
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Apr 2008
    Posts
    189
    Yeah, I thought about that.

    But I cannot do it, because I have a long list of combos that will go on and off depending another selection.

    Also, I will have all placed in the same position (left and top values): will be a mess.

    Is it possible to do the creation in "real time"?

  4. #4
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    I'm sure it's possible to do it, but I have never needed to so I'm not sure how it is best done. When I find more time I might take a shot and making something work and then I'll give you the code.

    Have you considered having one combo box and just morphing it as needed?

    I'm still convinced that there's an easier way to do it.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  5. #5
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185
    Star, I checked his code it works if from form1 run it and open form2 and put the control in form2, but when I run the code from form1 and want to put the control in the same form (i.e. form1) it raise the error.
    <<Never Walk on the Traveled Path, Because it only Leads you to where the Others have been.>>
    Graham Bell

  6. #6
    Join Date
    Apr 2008
    Posts
    189
    Quote Originally Posted by Aran1
    Star, I checked his code it works if from form1 run it and open form2 and put the control in form2, but when I run the code from form1 and want to put the control in the same form (i.e. form1) it raise the error.
    Yep, you are right.

  7. #7
    Join Date
    Apr 2008
    Posts
    189
    Quote Originally Posted by StarTrekker
    I'm sure it's possible to do it, but I have never needed to so I'm not sure how it is best done. When I find more time I might take a shot and making something work and then I'll give you the code.

    Have you considered having one combo box and just morphing it as needed?

    I'm still convinced that there's an easier way to do it.

    Combo: the user is not able to know what he can select.
    St*pid user

  8. #8
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Quote Originally Posted by Aran1
    Star, I checked his code it works if from form1 run it and open form2 and put the control in form2, but when I run the code from form1 and want to put the control in the same form (i.e. form1) it raise the error.
    So you can't edit the form when it is running in form view. Seems pretty logical to me, you're running Form1 in Form view and executing code while in form view that wants to take the form to Design view... which would stop the code.....

    See the problem?

    Quote Originally Posted by pepemosca
    Combo: the user is not able to know what he can select.
    St*pid user
    Well I must be stupid too because I can't understand where the problem is... why you need to create controls on the form you're currently in...

    Maybe you could elaborate on what you're doing, maybe with a screenshot or something so I can understand why/when you'd need to do this?
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  9. #9
    Join Date
    Apr 2008
    Posts
    189

    Red face

    Quote Originally Posted by StarTrekker
    So you can't edit the form when it is running in form view. Seems pretty logical to me, you're running Form1 in Form view and executing code while in form view that wants to take the form to Design view... which would stop the code.....

    See the problem?
    Actually, changing from acNormal to acDesign view: doesn't stop the code.
    I do a lot of silly changes on the form that I'm looking (Formulario1, for example) and I have to change from acNormal to acDesign: and no problem

    The problem is only with the CreateControl.

    But as far as I reed, what I want to do: cannot be done.
    I'll have to find a new way to solve my problem

    Well I must be stupid too because I can't understand where the problem is... why you need to create controls on the form you're currently in...
    I don't think so

    Maybe you could elaborate on what you're doing, maybe with a screenshot or something so I can understand why/when you'd need to do this?
    What I'm trying to do is make a unique form that changes the options depending on what information you would like to see.

    Is a production Form. So If you would like to see production: shows production fields... if you would like to see stock, shows stocks fields...

    Ideas?
    Thanks!

  10. #10
    Join Date
    Jun 2007
    Posts
    33
    Hi all

    Hide and show the controls

  11. #11
    Join Date
    Apr 2008
    Posts
    189
    Quote Originally Posted by PedroF
    Hi all

    Hide and show the controls
    Hello PedroF!
    As I see: will have to do that

  12. #12
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Goto Post 2

    So why not have different forms. If the user click Stock from the menu, they get the stock form. If they click Production from the menu, they get the production form. I still see no reason for this "problem" See!! I am stoooopid
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  13. #13
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    GoTo Post 4

    one combo, one form, switch the .rowsource at runtime to suit user selection.

    select case userSelection
    case 1
    me.mycombo.rowsource = "SELECT fldA, fldB FROM tblX ORDER BY fldB"
    case 2
    me.mycombo.rowsource = "SELECT ....etc

    you can also change .boundcolumn, .columncount, .columnwidths etc if needed.

    izy
    currently using SS 2008R2

  14. #14
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Yes.... a.k.a. morph the combo box as needed
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  15. #15
    Join Date
    Apr 2008
    Posts
    189
    Quote Originally Posted by izyrider
    GoTo Post 4

    one combo, one form, switch the .rowsource at runtime to suit user selection.

    select case userSelection
    case 1
    me.mycombo.rowsource = "SELECT fldA, fldB FROM tblX ORDER BY fldB"
    case 2
    me.mycombo.rowsource = "SELECT ....etc

    you can also change .boundcolumn, .columncount, .columnwidths etc if needed.

    izy
    Yes, I'm doing that: but I was thinking about creating new CheckBoxes.
    I'm right now doing that of "rowsource" and all that stuff... But I wanted to make some new CheckBoxes.

    Ideas?

    I'm thinking about creating blank checkboxes and make a "converter table" to get the real name.

Posting Permissions

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