Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2002
    Posts
    7

    Unanswered: Visible button conditional formatting

    I have a button hotlink to html page in a subform and I am trying to set a rule so that it will only display the button by the record if it has an invoice. and not display where the letter code in cTrantype does not equal "i". I am however having problem writing the correct syntax. Here is an example below does anyone have any ideas.

    If Forms![frm_TransactionSQL_subform]![cTrantype] = "i" Then
    Forms![frm_TransactionSQL_subform]![cmd_explorer].[Visible] = True
    Else
    Forms![frm_TransactionSQL_subform]![cmd_explorer].[Visible] = False
    End If

  2. #2
    Join Date
    Aug 2002
    Location
    Québec, Canada
    Posts
    109

    Re: Visible button conditional formatting

    Originally posted by Fud
    I have a button hotlink to html page in a subform and I am trying to set a rule so that it will only display the button by the record if it has an invoice. and not display where the letter code in cTrantype does not equal "i". I am however having problem writing the correct syntax. Here is an example below does anyone have any ideas.

    If Forms![frm_TransactionSQL_subform]![cTrantype] = "i" Then
    Forms![frm_TransactionSQL_subform]![cmd_explorer].[Visible] = True
    Else
    Forms![frm_TransactionSQL_subform]![cmd_explorer].[Visible] = False
    End If
    What's exactly the error? In that case, I suggest you change this for the following to take care of an invalid value

    Code:
    If Forms![frm_TransactionSQL_subform]![cTrantype] & "" = "i" Then
    Forms![frm_TransactionSQL_subform]![cmd_explorer].[Visible] = True
    Else
    Forms![frm_TransactionSQL_subform]![cmd_explorer].[Visible] = False
    End If
    JefB

  3. #3
    Join Date
    Jun 2002
    Posts
    7
    Thanks for the advice jef but still not working. It comes up with Runtime error2450 saying that it can't find the form refered to in the code.

  4. #4
    Join Date
    Oct 2001
    Location
    Chicago
    Posts
    440
    Forms![ParentFormName]![frm_TransactionSQL_subform]![cmd_explorer].Visible = True

  5. #5
    Join Date
    Aug 2002
    Location
    Québec, Canada
    Posts
    109
    you must ensure that the form you are trying to refer is open, the form should also be named exactly how you type it (if you change the name afterward, the code will not work). The form name is [frm_TransactionSQL_subform] and MUST be open when you refer to it

    JefB

  6. #6
    Join Date
    Jun 2002
    Posts
    7
    The form is name correctly i.e "frm_etc etc etc" and it is open at the time of operation as it is a sub form

  7. #7
    Join Date
    Oct 2001
    Location
    Chicago
    Posts
    440
    The situation is that fud is trying to reference a subform as part of the forms collection and it is not. You need to reference the subfom name and not the subform's source object. So if you swap the source object through code - you still reference the subform controls by the name of the subfom container - not the name of the form used as the subform.

    Forms![ParentFormName]![NameGivenToSubFormOnParentForm]![ControlNameOnSubform].Visible = True

    Run this sub and you will see that despite your subform being 'open', it is not part of the Forms collection and can not be references as such.

    Sub AllOpenForms()
    Dim frm As Form, ctl As Control

    ' Enumerate Forms collection.
    For Each frm In Forms
    ' Print name of form.
    Debug.Print frm.Name
    ' Enumerate Controls collection of each form.
    For Each ctl In frm.Controls
    ' Print name of each control.
    Debug.Print ">>>"; ctl.Name
    Next ctl
    Next frm
    End Sub

Posting Permissions

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