Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2007
    Posts
    8

    Unanswered: How to declare a form as a variable

    Hi everyone,

    I am sure this would be simple but maybe I have no idea what I am actually doing, never tried this before but the purpose to this code is to pull the form name and combo box to refresh from a table.

    I have mocked up an example of what Im trying to do as attached.

    The code:

    Dim frmName As Form
    Dim cboCombo As ComboBox

    frmName = "frmForm"
    cboCombo = "cboTest"

    Forms!frmForm!cboCombo.Refresh
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2007
    Posts
    8
    Just like to mention the code doesnt work.

    I am trying to set the form name and combo nox name to variables and use the following code:

    forms!FormName!ComboBoxName!Requery

    Basically I will have a table of a list of form names and combo boxes to perform a refresh on.

    I want to do this as I have a list editor that will add, edit and delete values used by the combo boxes.

    Cheers,

    Mark

  3. #3
    Join Date
    Jun 2003
    Location
    USA
    Posts
    1,032
    Hi ByteLogic and welcome to the forum!

    Seems like you'd want to change this:
    Code:
    Dim frmName As Form
    Dim cboCombo As ComboBox
    
    frmName = "frmForm"
    cboCombo = "cboTest"
    To be more like this instead:
    Code:
    Dim frmName As Form
    Dim cboCombo As ComboBox
    
    frmName.Name = "frmForm"
    cboCombo.Name = "cboTest"
    J. Paul Schmidt, Freelance Web and Database Developer
    www.Bullschmidt.com
    Access Database Sample, Web Database Sample, ASP Design Tips

  4. #4
    Join Date
    Nov 2007
    Posts
    8
    Hi,

    Thank you very much for the prompt reply.

    Just a question, say it was a subform:

    forms!frmParent!frmSubform!cboMyCombo.requery

    and I wanted to requery would I have code like this:

    dim frmParent as form
    dim frmChild as form
    dim cboCombo as combobox

    frmParent.Name = "frmParent"
    frmChild.Name = "frmSubform"
    cboCombo.Name = "cboMyCombo"

    forms!frmParent!frmChild!cboCombo.requery

    Sorry, I dont have access to access on this machine so I thought I would ask.

    Cheers,

    Mark

  5. #5
    Join Date
    Jun 2003
    Location
    USA
    Posts
    1,032
    Here's the syntax for referring to a control on a subform:
    Forms![MyForm]![MySubformControlOnTheMainForm].Form![MyControlOnTheSubform]

    And this can also be found by searching Access help for "Refer to objects in expressions."
    J. Paul Schmidt, Freelance Web and Database Developer
    www.Bullschmidt.com
    Access Database Sample, Web Database Sample, ASP Design Tips

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    If you want to assign an object to another (in this case a form) you should use a more regular sytax:

    Dim frm as Form
    Set frm = Forms![MyForm]

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by ByteLogic
    I am trying to set the form name and combo nox name to variables and use the following code:

    forms!FormName!ComboBoxName!Requery
    Did you get an answer to this Mark? Nothing looks like it to me, maybe I missed something.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  8. #8
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Quote Originally Posted by ByteLogic
    Just like to mention the code doesnt work.

    I am trying to set the form name and combo nox name to variables and use the following code:

    forms!FormName!ComboBoxName!Requery
    Hi

    Following on from poole's post, pehaps this will do it
    Code:
    Dim frmName As String
    Dim cboName As String
    
    frmName = "YourFormName"
    cboName = "cboBoxName"
    
    
    Forms(frmName).Controls(cboName).Requery

    ??

    Note the variable are strings


    MTB

  9. #9
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by MikeTheBike
    Code:
    Forms(frmName).Controls(cboName).Requery
    Exactly where I was going!

    Quote Originally Posted by MikeTheBike
    Following on from poole's post
    ...and it's pootle
    Last edited by pootle flump; 03-05-09 at 12:52.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  10. #10
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Quote Originally Posted by pootle flump
    Exactly where I was going!

    ...and it's pootle

    OOPS! sorry!

  11. #11
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Aw - I couldn't stay mad at you
    Testimonial:
    pootle flump
    ur codings are working excelent.

  12. #12
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Quote Originally Posted by pootle flump
    Aw - I couldn't stay mad at you
    Phew! I shall sleep easy(er) tonight!

    Cheers.

Posting Permissions

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