Can I have 2 then statements after each instruction?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NewtoAccess
    New Member
    • May 2007
    • 32

    Can I have 2 then statements after each instruction?

    How can I have an If/Then statement perform 2 commands instead of just one per conditional IF statement?

    Once a condition is true I want the then command to do 2 things not just one. The AND command doesnt work.

    If RecordCount = 0 And Forms!devicemai n![Category] = "Server" Then
    Forms!connect![PortA] = Me![PortID] THEN
    Forms!connect!S eeInterfaceZ.Fo rm.Visible = False

    ElseIf RecordCount = 0 And Forms!devicemai n![Category] = "Switch" Or Forms!devicemai n![Category] = "raritan" Then
    Forms!connect![PortZ] = Forms!portmain![PortID]
    End If


    Exit_connectto_ Click:
    Exit Sub

    Err_connectto_C lick:
    MsgBox Err.Description
    Resume Exit_connectto_ Click

    End Sub
  • Lysander
    Recognized Expert Contributor
    • Apr 2007
    • 344

    #2
    Originally posted by NewtoAccess
    How can I have an If/Then statement perform 2 commands instead of just one per conditional IF statement?

    Once a condition is true I want the then command to do 2 things not just one. The AND command doesnt work.

    If RecordCount = 0 And Forms!devicemai n![Category] = "Server" Then
    Forms!connect![PortA] = Me![PortID] THEN
    Forms!connect!S eeInterfaceZ.Fo rm.Visible = False

    ElseIf RecordCount = 0 And Forms!devicemai n![Category] = "Switch" Or Forms!devicemai n![Category] = "raritan" Then
    Forms!connect![PortZ] = Forms!portmain![PortID]
    End If


    Exit_connectto_ Click:
    Exit Sub

    Err_connectto_C lick:
    MsgBox Err.Description
    Resume Exit_connectto_ Click

    End Sub
    I may be mis-understanding the problem, but you can have as many statements as you like for each IF clause, including nested IF statements.

    The syntax is something like this
    [code=vb]
    if something-is-true or something-else-is-true then
    execute this statement
    execute this one as well
    keep executing statement till you get ELSE or END IF
    else
    As before, do this statement
    keep on going till you get END IF
    end if
    [/code]

    Comment

    • MMcCarthy
      Recognized Expert MVP
      • Aug 2006
      • 14387

      #3
      As Lysander says you don't need the second Then statement, you just list all the statements you want executed in the order you want to execute them.

      [code=vb]
      If RecordCount = 0 And Forms!devicemai n![Category] = "Server" Then
      Forms!connect![PortA] = Me![PortID]
      Forms!connect!S eeInterfaceZ.Fo rm.Visible = False
      ElseIf RecordCount = 0 And Forms!devicemai n![Category] = "Switch" Or Forms!devicemai n![Category] = "raritan" Then
      Forms!connect![PortZ] = Forms!portmain![PortID]
      End If


      Exit_connectto_ Click:
      Exit Sub

      Err_connectto_C lick:
      MsgBox Err.Description
      Resume Exit_connectto_ Click

      End Sub[/code]

      Comment

      • NewtoAccess
        New Member
        • May 2007
        • 32

        #4
        Still doesnt work.

        Subform SEEINTERFACEZ always disappears regardless if record >0
        here is the entire code:
        [CODE=vb] Private Sub connectto_Click ()
        On Error GoTo Err_connectto_C lick

        Dim stDocName As String
        Dim stLinkCriteria As String

        stDocName = "Connect"

        stLinkCriteria = "[PortA]=" & Me![PortID] & "or [PortZ]=" & Me![PortID]
        DoCmd.OpenForm stDocName, , , stLinkCriteria

        If RecordCount = 0 And Forms!devicemai n![Category] = "Server" Then
        Forms!connect![PortA] = Me![PortID]
        Forms!connect!S eeInterfaceZ.Fo rm.Visible = False
        ElseIf RecordCount = 0 And Forms!devicemai n![Category] = "Switch" Or Forms!devicemai n![Category] = "raritan" Then
        Forms!connect![PortZ] = Me![PortID]
        Forms!connect!S eeInterfaceA.Fo rm.Visible = False
        End If

        Exit_connectto_ Click:
        Exit Sub

        Err_connectto_C lick:
        MsgBox Err.Description
        Resume Exit_connectto_ Click

        End Sub
        [/CODE]

        Comment

        • MMcCarthy
          Recognized Expert MVP
          • Aug 2006
          • 14387

          #5
          You have to put this in the load event of the Connect form. You can't get the record count from outside the form.

          [code=vb]
          Private Sub Form_Load()
          Dim rs As DAO.Recordset

          Set rs = Me.RecordsetClo ne

          If rs.RecordCount = 0 Then
          If Forms!devicemai n![Category] = "Server" Then
          Me![PortA] = Forms!devicemai n![PortID]
          Me!SeeInterface Z.Form.Visible = False
          ElseIf Forms!devicemai n![Category] = "Switch" Or Forms!devicemai n![Category] = "raritan" Then
          Me![PortZ] = Forms!devicemai n![PortID]
          Me!SeeInterface A.Form.Visible = False
          End If
          End If

          Set rs = Nothing

          End Sub
          [/CODE]

          Comment

          • NewtoAccess
            New Member
            • May 2007
            • 32

            #6
            THANKS mmccarthy !

            It worked like a charm. I really need to read-up on the what 'oncurrent', 'onload' etc mean. I was working on this for 2-weeks.

            Thanks Again!

            Comment

            • MMcCarthy
              Recognized Expert MVP
              • Aug 2006
              • 14387

              #7
              Originally posted by NewtoAccess
              THANKS mmccarthy !

              It worked like a charm. I really need to read-up on the what 'oncurrent', 'onload' etc mean. I was working on this for 2-weeks.

              Thanks Again!
              No problem

              Comment

              Working...