Results 1 to 11 of 11
  1. #1
    Join Date
    May 2004
    Posts
    73

    Question Unanswered: How do you make a control visible or not?

    In VB you make a label visible or not by using:

    Me.SomeLabel.Visible = True or False

    But when I try that with a control:

    Me.SomeControl.Visible = True or False

    I get:

    Compile Error:
    Method or data member not found

    Can someone please tell me how to do this the right way?

    Thanks

  2. #2
    Join Date
    Jul 2004
    Location
    Southampton, UK
    Posts
    368
    Hi

    Try:

    Me!SomeControl.Visible = True

    Me!SomeControl.Visible = False

    Note the exclamation mark instead of full stop after me.

    HTH
    Chris

  3. #3
    Join Date
    May 2004
    Posts
    73
    Sorry no dice on that one, here was the error:
    Object does not support this property or method



    Here is the code I used:

    If Me.RMA_TO_MFG_VIA.Value = "UPS GROUND" And IsNull(RMA_TO_MFG_DATE) Then
    Me!RMA_TO_MFG_VIA.Visible = False
    Me.NOT_APPLICABLE_LABEL.Visible = True
    End If
    Last edited by X-Centric; 11-10-04 at 15:45.

  4. #4
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Which line is highlighted if you debug? What kind of control is it? Textbox? Combo Box? List Box?

  5. #5
    Join Date
    May 2004
    Posts
    73
    Me!RMA_TO_MFG_VIA.Visible = False

    Its not anything because it is a report, simply for visual reference.

    Thanks

  6. #6
    Join Date
    Oct 2003
    Posts
    81
    If it is a report, right click on the control, select properties, select the "all" tab, scroll down until you see the visible control and select no.

  7. #7
    Join Date
    May 2004
    Posts
    73
    Thanks for that last post but i need to switch the property from VB inside the report.

  8. #8
    Join Date
    Jul 2004
    Location
    Southampton, UK
    Posts
    368
    Quote Originally Posted by X-Centric
    Here is the code I used:
    If Me.RMA_TO_MFG_VIA.Value = "UPS GROUND" And IsNullRMA_TO_MFG_DATE) Then
    Me!RMA_TO_MFG_VIA.Visible = False
    Me.NOT_APPLICABLE_LABEL.Visible = True
    End If
    You still have full stops after the Me bit. You must use an exclamation mark. So your code should read:

    Code:
    If Me!RMA_TO_MFG_VIA.Value = "UPS GROUND" And IsNull(Me!RMA_TO_MFG_DATE.Value) Then
    Me!RMA_TO_MFG_VIA.Visible = False
    Me!NOT_APPLICABLE_LABEL.Visible = True
    End If
    Also, the report you are changing the properties on must be open. If your VB is in one of the reports' events then you should be ok. However, if the report is open but you are running code from say a button on a form, the you must refer to the reports properties by their full description e.g.
    reports!myReport!RMA_TO_MFG_VIA.Value

    HTH

  9. #9
    Join Date
    May 2004
    Posts
    73
    That did the trick, thanls alot. Could you please describe the difference between using the "!" and "." in the expression? So I know not to make that mistake again?

    Much appreciated.

  10. #10
    Join Date
    Sep 2004
    Location
    Dallas, TX
    Posts
    77

    I got this from somewhere, hope this helps

    The bang ("!") and dot (".") identifier operators help describe the relationships among collections, objects, and properties in an expression. They indicate that one part of an expression belongs to another.

    In general, you follow the bang with the name of something you created: a form, report, or control. The bang also indicates that the item to follow is an element of a collection. You'll usually follow the dot with a property, collection, or method name. Actually, under the covers, the bang separator really says, "retrieve the following object from the default collection of the parent object." (See the section "Using Default Collections" later in this chapter.) For example, when working with forms, you can refer to a control on a form like this:

    Set ctl = Forms("frmTest").Controls("txtName")

    or, because Controls is the default collection of a form, you can abbreviate that as either of the following:

    Set ctl = Forms("frmTest")("txtName")
    Set ctl = Forms("frmTest")!txtName

    You can also think of the uses of these operators this way: a bang (or parentheses and quotes) separates an object from the collection it's in (a field in a table, a form in the Forms collection, a control on a form), while a dot separates an object from a property, method, or collection of that object.

    If you refer back to Table 6.2, you'll see that there's always an alternative to using the bang operator: you can use the parentheses and quotes syntax. For example, these two statements refer to exactly the same property:

    cat.Tables!tblCustomers.Columns!Address.Type
    cat.Tables("tblCustomers").Columns("Address").Type

    It turns out that, behind the scenes, the former style of dot-and-bang reference is translated to the latter style of parentheses-and-quotes reference when you execute such a statement. This means that, although using the bang operator will save you a bit of typing, you'll pay for it in a speed penalty. Our recommendation, and the style we've followed throughout this book, is to always use the parentheses and quotes format for referring to a member of a collection unless it's absolutely necessary to use the bang operator. In addition, if the object to which you're referring contains spaces (or other nonstandard characters), you'll have to treat these names specially when using the bang syntax—you'll need to surround the name in square brackets. If you use the parentheses/quotes syntax, all names are treated equally.

    WARNING One place where the bang operator is necessary is in query parameters that refer to form fields. That is, you cannot avoid the Forms!FormName!ControlName syntax in this case.

    Tip It's a hard habit to break—we've been using "!" since Access 1. But the fact is, except in a very few places (query parameters is the one that comes to mind) you needn't ever use a bang and should probably think about weaning yourself from this syntax if you currently use it. It's important that you understand what it's doing and what it means when you see it, but we suggest you not use it in your VBA code.

  11. #11
    Join Date
    May 2004
    Posts
    73
    Thansk for everyones help. This forum rocks! You guys are always there for me. I have been able to help a few out myself. Happy coding!!!

Posting Permissions

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