0

Hello I am having an error with this code at the Line Else I want it to change the caption if a name has been entered if not then exit

Private Sub cmdButton_Click()

    Dim name As String

    With cmdButton

    If .Caption = "CommandButton1" Then

        name = InputBox("Enter Template Name.")

    End If

    If StrPtr(name) = 0& Then Exit Sub

    Else
        .Caption = name

    End If

    End With

    End Sub

1 Answer 1

1
If Len(name) = 0 Then  'exit sub if user doesn't enter a name (or cancels)
 Exit Sub
Else
 .Caption = name
End If
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you I will accept the answer in 2 minutes when it lets me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.