1

When I debug, it stops on the Elseif line and highlights me.cboKillRemaining.

I think this problem is self contained in my code below.

Dim Result As String
Dim Path As String

'Determine path
If (IsNull(Me.cboKillRemaining) Or Me.cboKillRemaining = "No") And Me.txtRemClones > 0 Then
    Result = MsgBox("Create " & Me.txtNumofTags & " tags from " & Me.cboGroup & " and leave remaining " & Me.txtRemClones & " clones active?", vbYesNo, "Confirm transplant")
    If Result = vbYes Then Path = 1
    Else: Path = 4
    End If
    
ElseIf Me.txtRemClones > 0 And Me.cboKillRemaining = "Yes" Then
    Result = MsgBox("Create " & Me.txtNumofTags & " tags from " & Me.cboGroup & ", kill remaining " & Me.txtRemClones & ", and inactivate clone group?", vbYesNo, "Confirm transplant")
    If Result = vbYes Then Path = 2
    Else: Path = 4
    End If
    
Else 'None remaining do not need to ask to kill clones
    Result = MsgBox("Create " & Me.txtNumofTags & " tags from " & Me.cboGroup & " and inactivate clone group?", vbYesNo, "Confirm transplant")
    If Result = vbYes Then Path = 3
    Else: Path = 4
    End If
End If
Community
  • 1
  • 1
MJ B
  • 19
  • 4
  • 3
    `If Result = vbYes Then Path = 1` - move `Path = 1` to a new line. Same for `If Result = vbYes Then Path = 2` and `If Result = vbYes Then Path = 3`. – BigBen Apr 10 '20 at 15:49
  • 1
    just for fun, `If Result = vbYes Then Path = 3: Else Path = 4: End If` will also work. but that's not always so readable. – Scott Holtzman Apr 10 '20 at 15:50
  • [This answer](https://stackoverflow.com/a/52506939/9245853) is helpful. – BigBen Apr 10 '20 at 15:58

1 Answers1

1

You should not use the obtuse syntax, it is not common. Spend a few more lines, and you should be set. Also, adjust the declarations:

Dim Result As VbMsgBoxResult
Dim Path As Integer

    'Determine path
    If (IsNull(Me.cboKillRemaining) Or Me.cboKillRemaining = "No") And Me.txtRemClones > 0 Then
        Result = MsgBox("Create " & Me.txtNumofTags & " tags from " & Me.cboGroup & " and leave remaining " & Me.txtRemClones & " clones active?", vbYesNo, "Confirm transplant")
        If Result = vbYes Then 
            Path = 1
        Else
            Path = 4
        End If

    ElseIf Me.txtRemClones > 0 And Me.cboKillRemaining = "Yes" Then
        Result = MsgBox("Create " & Me.txtNumofTags & " tags from " & Me.cboGroup & ", kill remaining " & Me.txtRemClones & ", and inactivate clone group?", vbYesNo, "Confirm transplant")
        If Result = vbYes Then 
            Path = 2
        Else
            Path = 4
        End If

    Else 'None remaining do not need to ask to kill clones
        Result = MsgBox("Create " & Me.txtNumofTags & " tags from " & Me.cboGroup & " and inactivate clone group?", vbYesNo, "Confirm transplant")
        If Result = vbYes Then 
            Path = 3
        Else
            Path = 4
        End If
    End If
Gustav
  • 53,498
  • 7
  • 29
  • 55
  • 1
    That worked! Thank you so much. I didn't know I couldn't have it all on one line like that. – MJ B Apr 10 '20 at 15:57