Hiding a command button linking forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • danthrom

    Hiding a command button linking forms

    Hi all,

    I am trying to hid a command button which links two forms. The forms
    are connected by a one-to-many relationship and the second form has
    details on the first. But if no details are avaliable I don't want the
    command button to appear. I've been working with an "If/Then"
    statment, but now the command button never appears.

    Here is the statement I have

    Private Sub Form_Current()

    Dim stDocName As String

    stDocName = "Destroyed Files Contents"

    If "[Matter Number]" = Me![Matter Number] Then
    Destroyed_Form. Visible = True
    Else
    Destroyed_Form. Visible = False
    End If

    End Sub

    this is the statement linking the two forms

    Private Sub Destroyed_Form_ Click()
    On Error GoTo Err_Destroyed_F orm_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Destroyed Files Contents"

    stLinkCriteria = "[Matter Number]=" & "'" & Me![Matter Number] &
    "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_Destroyed_ Form_Click:
    Exit Sub

    Err_Destroyed_F orm_Click:
    MsgBox Err.Description
    Resume Exit_Destroyed_ Form_Click

    End Sub


    Thanks for any help,

    Danthrom

  • ManningFan

    #2
    Re: Hiding a command button linking forms

    Your problem lies here:
    If "[Matter Number]" = Me![Matter Number] Then

    Me![Matter Number] is never going to equal "[Matter Number]" because
    it's text. I think you want the value for [Matter Number], you don't
    want to pass it a text string. You probably want something like:
    If Forms!SubForm.[Matter Number] = Me![Matter Number] then

    I'm most likely wrong on the exact syntax but it's something along
    those lines.

    danthrom wrote:
    Hi all,
    >
    I am trying to hid a command button which links two forms. The forms
    are connected by a one-to-many relationship and the second form has
    details on the first. But if no details are avaliable I don't want the
    command button to appear. I've been working with an "If/Then"
    statment, but now the command button never appears.
    >
    Here is the statement I have
    >
    Private Sub Form_Current()
    >
    Dim stDocName As String
    >
    stDocName = "Destroyed Files Contents"
    >
    If "[Matter Number]" = Me![Matter Number] Then
    Destroyed_Form. Visible = True
    Else
    Destroyed_Form. Visible = False
    End If
    >
    End Sub
    >
    this is the statement linking the two forms
    >
    Private Sub Destroyed_Form_ Click()
    On Error GoTo Err_Destroyed_F orm_Click
    >
    Dim stDocName As String
    Dim stLinkCriteria As String
    >
    stDocName = "Destroyed Files Contents"
    >
    stLinkCriteria = "[Matter Number]=" & "'" & Me![Matter Number] &
    "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    >
    Exit_Destroyed_ Form_Click:
    Exit Sub
    >
    Err_Destroyed_F orm_Click:
    MsgBox Err.Description
    Resume Exit_Destroyed_ Form_Click
    >
    End Sub
    >
    >
    Thanks for any help,
    >
    Danthrom

    Comment

    • danthrom

      #3
      Re: Hiding a command button linking forms

      I tried

      If Forms![Destroyed Files Contents].[Matter Number] = Me![Matter
      Number] Then
      Destroyed_Form. Visible = True
      Else
      Destroyed_Form. Visible = False
      End If

      But it says that the form cannot be found, however the wording is fine.

      anymore suggestions?

      ManningFan wrote:
      Your problem lies here:
      If "[Matter Number]" = Me![Matter Number] Then
      >
      Me![Matter Number] is never going to equal "[Matter Number]" because
      it's text. I think you want the value for [Matter Number], you don't
      want to pass it a text string. You probably want something like:
      If Forms!SubForm.[Matter Number] = Me![Matter Number] then
      >
      I'm most likely wrong on the exact syntax but it's something along
      those lines.
      >
      danthrom wrote:
      Hi all,

      I am trying to hid a command button which links two forms. The forms
      are connected by a one-to-many relationship and the second form has
      details on the first. But if no details are avaliable I don't want the
      command button to appear. I've been working with an "If/Then"
      statment, but now the command button never appears.

      Here is the statement I have

      Private Sub Form_Current()

      Dim stDocName As String

      stDocName = "Destroyed Files Contents"

      If "[Matter Number]" = Me![Matter Number] Then
      Destroyed_Form. Visible = True
      Else
      Destroyed_Form. Visible = False
      End If

      End Sub

      this is the statement linking the two forms

      Private Sub Destroyed_Form_ Click()
      On Error GoTo Err_Destroyed_F orm_Click

      Dim stDocName As String
      Dim stLinkCriteria As String

      stDocName = "Destroyed Files Contents"

      stLinkCriteria = "[Matter Number]=" & "'" & Me![Matter Number] &
      "'"
      DoCmd.OpenForm stDocName, , , stLinkCriteria

      Exit_Destroyed_ Form_Click:
      Exit Sub

      Err_Destroyed_F orm_Click:
      MsgBox Err.Description
      Resume Exit_Destroyed_ Form_Click

      End Sub


      Thanks for any help,

      Danthrom

      Comment

      Working...