+ Reply to Thread
Results 1 to 3 of 3

Thread: still saving a record to excel even if i press the NO button

  1. #1
    Forum Contributor
    Join Date
    05-22-2006
    Posts
    103

    still saving a record to excel even if i press the NO button

    hi....
    im working on a project right now and one of its functions is to add persons on the worksheet....my problem is, how can i stop excel from adding the person i input if i press Close or No button?...because what is happening now is that, even if i press the close or no button, still, that record is added on the worksheet, below is the source code, please advise:

    Sub Button5_Click()

    Dim i As Integer
    Dim results As Integer
    results = MsgBox("Are you sure you want to add new employee?", vbQuestion, "Add New Employee")

    If results = vbOK Then

    i = 4
    Do While Worksheets("EmployeeDatabase").Range("A" & i) <> ""
    i = i + 1
    Loop
    Worksheets("EmployeeDatabase").Unprotect
    Worksheets("EmployeeDatabase").Range("A" & i) = Worksheets("AddNew").Range("G12")
    Worksheets("EmployeeDatabase").Range("B" & i) = Worksheets("AddNew").Range("G16")
    Worksheets("EmployeeDatabase").Range("C" & i) = Worksheets("AddNew").Range("G14")
    Worksheets("EmployeeDatabase").Range("D" & i) = Worksheets("AddNew").Range("G15")
    Worksheets("EmployeeDatabase").Range("E" & i) = Worksheets("AddNew").Range("G13")
    Worksheets("EmployeeDatabase").Range("F" & i) = Worksheets("AddNew").Range("G17")
    Sheets("AddNew").Select
    Range("G13:G16").Select
    Selection.ClearContents
    Range("G13").Select
    End If
    Worksheets("EmployeeDatabase").Protect
    End Sub

  2. #2
    Don Guillett
    Guest

    Re: still saving a record to excel even if i press the NO button

    try
    Sub checkmsgbox()
    Dim i As Integer
    results = MsgBox("Are you sure you want to add new employee?", vbYesNo)
    If results = vbYes Then MsgBox "OK"
    End Sub


    --
    Don Guillett
    SalesAid Software
    dguillett1@austin.rr.com
    "tweety127" <tweety127.29ce3d_1150204810.8343@excelforum-nospam.com> wrote
    in message news:tweety127.29ce3d_1150204810.8343@excelforum-nospam.com...
    >
    > hi....
    > im working on a project right now and one of its functions is to add
    > persons on the worksheet....my problem is, how can i stop excel from
    > adding the person i input if i press Close or No button?...because what
    > is happening now is that, even if i press the close or no button, still,
    > that record is added on the worksheet, below is the source code, please
    > advise:
    >
    > Sub Button5_Click()
    >
    > Dim i As Integer
    > Dim results As Integer
    > results = MsgBox("Are you sure you want to add new employee?",
    > vbQuestion, "Add New Employee")
    >
    > If results = vbOK Then
    >
    > i = 4
    > Do While Worksheets("EmployeeDatabase").Range("A" & i) <> ""
    > i = i + 1
    > Loop
    > Worksheets("EmployeeDatabase").Unprotect
    > Worksheets("EmployeeDatabase").Range("A" & i) =
    > Worksheets("AddNew").Range("G12")
    > Worksheets("EmployeeDatabase").Range("B" & i) =
    > Worksheets("AddNew").Range("G16")
    > Worksheets("EmployeeDatabase").Range("C" & i) =
    > Worksheets("AddNew").Range("G14")
    > Worksheets("EmployeeDatabase").Range("D" & i) =
    > Worksheets("AddNew").Range("G15")
    > Worksheets("EmployeeDatabase").Range("E" & i) =
    > Worksheets("AddNew").Range("G13")
    > Worksheets("EmployeeDatabase").Range("F" & i) =
    > Worksheets("AddNew").Range("G17")
    > Sheets("AddNew").Select
    > Range("G13:G16").Select
    > Selection.ClearContents
    > Range("G13").Select
    > End If
    > Worksheets("EmployeeDatabase").Protect
    > End Sub
    >
    >
    > --
    > tweety127
    > ------------------------------------------------------------------------
    > tweety127's Profile:
    > http://www.excelforum.com/member.php...o&userid=34673
    > View this thread: http://www.excelforum.com/showthread...hreadid=551394
    >




  3. #3
    Die_Another_Day
    Guest

    Re: still saving a record to excel even if i press the NO button

    Change this:
    results = MsgBox("Are you sure you want to add new employee?",
    vbQuestion, "Add New Employee")

    to this:
    results = MsgBox("Are you sure you want to add new employee?",
    vbYesNo, "Add New Employee")

    and this:
    If results = vbOK Then
    to this:
    If results = vbYes Then

    HTH

    Die_Another_Day

    tweety127 wrote:
    > hi....
    > im working on a project right now and one of its functions is to add
    > persons on the worksheet....my problem is, how can i stop excel from
    > adding the person i input if i press Close or No button?...because what
    > is happening now is that, even if i press the close or no button, still,
    > that record is added on the worksheet, below is the source code, please
    > advise:
    >
    > Sub Button5_Click()
    >
    > Dim i As Integer
    > Dim results As Integer
    > results = MsgBox("Are you sure you want to add new employee?",
    > vbQuestion, "Add New Employee")
    >
    > If results = vbOK Then
    >
    > i = 4
    > Do While Worksheets("EmployeeDatabase").Range("A" & i) <> ""
    > i = i + 1
    > Loop
    > Worksheets("EmployeeDatabase").Unprotect
    > Worksheets("EmployeeDatabase").Range("A" & i) =
    > Worksheets("AddNew").Range("G12")
    > Worksheets("EmployeeDatabase").Range("B" & i) =
    > Worksheets("AddNew").Range("G16")
    > Worksheets("EmployeeDatabase").Range("C" & i) =
    > Worksheets("AddNew").Range("G14")
    > Worksheets("EmployeeDatabase").Range("D" & i) =
    > Worksheets("AddNew").Range("G15")
    > Worksheets("EmployeeDatabase").Range("E" & i) =
    > Worksheets("AddNew").Range("G13")
    > Worksheets("EmployeeDatabase").Range("F" & i) =
    > Worksheets("AddNew").Range("G17")
    > Sheets("AddNew").Select
    > Range("G13:G16").Select
    > Selection.ClearContents
    > Range("G13").Select
    > End If
    > Worksheets("EmployeeDatabase").Protect
    > End Sub
    >
    >
    > --
    > tweety127
    > ------------------------------------------------------------------------
    > tweety127's Profile: http://www.excelforum.com/member.php...o&userid=34673
    > View this thread: http://www.excelforum.com/showthread...hreadid=551394



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0