+ Reply to Thread
Results 1 to 10 of 10

Toggle Button Does not Toggle OFF when Clicked

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-19-2013
    Location
    Philadelphia
    MS-Off Ver
    Excel 2010
    Posts
    201

    Toggle Button Does not Toggle OFF when Clicked

    I have two option buttons that can be clicked if either criteria is true. However, if it is clicked accidently, it cannot be unclicked. If i click one, the other will unclick, but I can't UN-click both of them at the same time. Do i need to add code or change the button?

    Full File Attached (.zip)

    below is my existing code. I do have one [checkbox] that toggles on and off and I'm wondering if i need to replace the option buttons with check boxes. (?)


    Private Sub ButtonSave_Click()
        Dim NextFreeRow As Long
        Dim Rng As Range
        Dim ws As Worksheet, ws1 As Worksheet
        Dim Answer As String
        Dim x As Long
        Dim oSh As Worksheet
        Dim cel As Range
        Dim lo As ListObject
        Dim loRowNum As Long
    
    
        Set ws = Sheets("YourJobLog")
    
        If Me.CBTravel.ListIndex = 0 And Me.TBNotOnList = "" Then
            MsgBox "Gotta Enter Mileage"
            Me.TBNotOnList.SetFocus
            Exit Sub
        End If
    
    
        With ws
            Set Rng = .ListObjects(1).ListColumns(1).Range
            NextFreeRow = Rng.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row + 1
    
            Set oSh = ws
            Set cel = oSh.Cells(NextFreeRow - 1, 2)
            If cel.ListObject Is Nothing Then
                Exit Sub
            End If
            Set lo = cel.ListObject
            With lo
                loRowNum = cel.Row - .HeaderRowRange.Row
            End With
            With oSh.ListObjects("Table3373839404123234567824")
                x = .ListRows.Count
                If x = loRowNum Then
                    Application.EnableEvents = False
                    ws.Unprotect "admin"
                    .ListRows.Add AlwaysInsert:=True
                    ws.Protect "admin"
                    Application.EnableEvents = True
                End If
            End With
    
            .Cells(NextFreeRow, 2) = CBJobVenue.Text
            .Cells(NextFreeRow, 3) = TBDate.Text
            .Cells(NextFreeRow, 4) = TBStartTime.Text
            .Cells(NextFreeRow, 5) = TBEndingTime.Text
            .Cells(NextFreeRow, 7) = CBInterpreterName.Text
            .Cells(NextFreeRow, 8) = CBLanguage.Text
            .Cells(NextFreeRow, 9) = TBPatientName.Text
            .Cells(NextFreeRow, 10) = CBGender.Text
            .Cells(NextFreeRow, 11) = CBCampus.Text
            .Cells(NextFreeRow, 12) = TBDepartment.Text
            .Cells(NextFreeRow, 13) = CBRoom.Text
            .Cells(NextFreeRow, 14) = CBTravel.Text
            
            If Me.TBNotOnList <> "" Then
    
                On Error Resume Next
                Application.DisplayAlerts = False
    
                Answer = Application.InputBox _
                         (Prompt:="Please Enter a Description" & vbCrLf & "      of your travel", _
                          Title:="Where Did You Travel", Type:=2)
                On Error GoTo 0
                Application.DisplayAlerts = True
    
                If Answer = "" Or Answer = vbNullString Then
                    Exit Sub
                Else
                End If
                .Cells(NextFreeRow, "N") = Answer
                .Cells(NextFreeRow, "P").Value = Me.TBNotOnList.Value
            End If
    
            .Cells(NextFreeRow, 17) = TBFlexTime.Text
            .Cells(NextFreeRow, 18) = TBBonusTime.Text
            .Cells(NextFreeRow, 19) = OptButCancelled.Value
            .Cells(NextFreeRow, 20) = OptButNoShow.Value
            .Cells(NextFreeRow, 21) = TBNotes.Text
            If Me.CheckBox1.Value = True Then
                .Cells(NextFreeRow, 15).Value = 2
            Else
                .Cells(NextFreeRow, 15).Value = 1
            End If
    
        End With
        response = MsgBox("One Job has been successfully entered into your Job Log.  Do you want to enter another Job?", _
                          vbYesNo)
    
        If response = vbYes Then
            CBJobVenue.Text = ""
            TBDate.Text = ""
            TBStartTime.Text = ""
            TBEndingTime.Text = ""
            CBInterpreterName.Text = ""
            CBLanguage.Text = ""
            TBPatientName.Text = ""
            CBGender.Text = ""
            CBCampus.Text = ""
            TBDepartment.Text = ""
            CBRoom.Text = ""
            CBTravel.Text = ""
            TBFlexTime.Text = ""
            TBBonusTime.Text = ""
            OptButCancelled.Value = False
            OptButNoShow.Value = False
            TBNotes.Text = ""
            Me.TBNotOnList.Value = ""
            Me.CheckBox1.Value = False
    
    
            CBJobVenue.SetFocus
    
        Else
            Unload Me
        End If
    
    End Sub
    Last edited by robbfamily; 06-12-2014 at 08:43 AM.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Toggle Button Does not Toggle OFF when Clicked

    I do have one [checkbox] that toggles on and off and I'm wondering if i need to replace the option buttons with check boxes. (?)
    That would be the simplest solution since optionbuttons do work the way you describe.
    David
    (*) Reputation points appreciated.

  3. #3
    Forum Contributor
    Join Date
    12-19-2013
    Location
    Philadelphia
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Toggle Button Does not Toggle OFF when Clicked

    thansk tinbendr

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Toggle Button Does not Toggle OFF when Clicked

    Hi David

    The Code in the attached has been revised to include two new Check Boxes to replace the two Option Buttons in UserFormJogLogInput.

    Test it to make certain all works as desired; if so distribute the Changes.

    To distribute the Changes I'd recommend this:

    From the attached File, export UserFormJogLogInput to a Folder (or your Desktop). Any place that you'll remember where you put it.

    Open a COPY of an Actual Job Log Workbook of one of your Users...you can allow Macros or not, your choice.
    • Delete UserFormJogLogInput from this copy...don't export the UserForm.
    • Import the UserFormJogLogInput from the Location where you saved it.
    • Save and close this Copy.
    • Reopen the saved Copy...the Revised UserForm and Code should now reside in the Copy.
    • Assuming all is ok, back up the Users Live Files and update in the same manner.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Forum Contributor
    Join Date
    12-19-2013
    Location
    Philadelphia
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Toggle Button Does not Toggle OFF when Clicked

    John,
    I tested your solution on my workbook. as you described, and it works. No error messages. Good solution.

    I wasnt' sure what you meant by your final instruction bullet
    " ... backup the Users Live Files and update in the same manner."
    I'll be starting the new commercial thread within the next 10 minutes

    David

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Toggle Button Does not Toggle OFF when Clicked

    Hi David

    What I meant by this is to first backup the User's Workbook case things go to H in a hand basket. I believe the approach I suggested will work...or not...
    " ... backup the Users Live Files and update in the same manner."

  7. #7
    Forum Contributor
    Join Date
    12-19-2013
    Location
    Philadelphia
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Toggle Button Does not Toggle OFF when Clicked

    John, also, ....how do i delete old attachments on the forum website?

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Toggle Button Does not Toggle OFF when Clicked

    Hi David

    I've not used this but, if you go to "Settings" (upper Right hand corner) that'll bring up a Screen. In the Left hand Column, down at the bottom, you'll see "Attachments". Click that and it'll display all of your Attachments. It also gives you the option to delete Attachments.

    May I ask "Why"?

  9. #9
    Forum Contributor
    Join Date
    12-19-2013
    Location
    Philadelphia
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Toggle Button Does not Toggle OFF when Clicked

    Jaslake,

    a question. do you know what code i might need to add (and where) for the clicked "cancelled" and "NO Show" boxes to clear with the new form. it currently shows whatever the box was when a new record starts in the UserForm.

    David

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Toggle Button Does not Toggle OFF when Clicked

    Hi David

    I'd suggest this
    Private Sub CommandButton2_Click()
      Sheets("menu").Visible = True
      Sheets("menu").Select
      Unload Me
      'UserFormJobLogInput.Hide
    End Sub
    and this
    Private Sub UserForm_Initialize()
      Me.CheckBox1.Value = False
      Me.CheckBox2.Value = False
      Me.CheckBox3.Value = False
    End Sub
    Where are we on this?
    http://www.excelforum.com/commercial...ort-error.html

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 02-13-2014, 10:55 PM
  2. [SOLVED] Toggle Button
    By SZBELL in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-10-2013, 10:33 AM
  3. Toggle Button
    By aftabn10 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-02-2010, 07:10 AM
  4. Need help using a toggle button
    By tanktata in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-28-2006, 03:01 PM
  5. [SOLVED] Toggle Button
    By NavEx in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-22-2006, 09:45 PM

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.6.0 RC 1