+ Reply to Thread
Results 1 to 10 of 10

Spin Down Event skipping one record

Hybrid View

  1. #1
    Registered User
    Join Date
    07-31-2014
    Location
    Ephrata, PA
    MS-Off Ver
    2007
    Posts
    7

    Spin Down Event skipping one record

    I am creating a VBA userform and using a table as a database. I have a spin button created with both SpinDown and SpinUp Subs that allow me to scroll through the database records. When the form initializes, it shows the most recently added transaction on file. When pressing the SpinDown button, one record is skipped, i.e. if the last record is 100 and SpinDown is pressed 98 shows, not 99. Continuing to SpinUp or SpinDown and 99 will show, just not on the first SpinDown event. Other than this, the spin button works fine. Same exact scenario when a new record is added.

    Does anyone have any general ideas of what might be wrong? I know I can post the code and someone can help, but I'm trying to figure this out on my own, maybe with a few clues.

    If need be I will post my code.

    Thank you in advance for your help.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Spin Down Event skipping one record

    Can you determine if the Sub is triggered twice or is it moving two records for one execution?

    Post the code please.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Spin Down Event skipping one record

    Can you determine if the Sub is triggered twice or is it moving two records for one execution?

    Are there any other event procedures for the SpinButton other than the SpinUp and SpinDown procedures?

    Post the code please.

  4. #4
    Registered User
    Join Date
    07-31-2014
    Location
    Ephrata, PA
    MS-Off Ver
    2007
    Posts
    7

    Re: Spin Down Event skipping one record

    Code attached. Thanks.

    Option Explicit
     
    Dim Sh As Worksheet
    Dim CurrentRow As Long
    Dim MaxRows As Long
    Dim lrow As Long
    Dim ws As Worksheet
    Dim iRow As Long
    Private Sub UserForm_Initialize()
     Range("A2").Select
     Do Until ActiveCell.Value = ""
     ActiveCell.Offset(1, 0).Select
     Loop
    ActiveCell.Offset(-1, 0).Activate
    recnum.Value = ActiveCell.Value
    SpinButton1.Value = recnum.Value
    issuer.Value = ActiveCell.Offset(0, 1).Value
    driver.Value = ActiveCell.Offset(0, 2).Value
    so1.Value = ActiveCell.Offset(0, 3).Value
    so2.Value = ActiveCell.Offset(0, 4).Value
    so3.Value = ActiveCell.Offset(0, 5).Value
    so4.Value = ActiveCell.Offset(0, 6).Value
    so5.Value = ActiveCell.Offset(0, 7).Value
    so6.Value = ActiveCell.Offset(0, 8).Value
    so7.Value = ActiveCell.Offset(0, 9).Value
    so8.Value = ActiveCell.Offset(0, 10).Value
    so9.Value = ActiveCell.Offset(0, 11).Value
    so10.Value = ActiveCell.Offset(0, 12).Value
    location.Value = ActiveCell.Offset(0, 13).Value
    purpose.Value = ActiveCell.Offset(0, 14).Value
    checkno.Value = ActiveCell.Offset(0, 15).Value
    expresscode.Value = ActiveCell.Offset(0, 16).Value
    remarks.Value = ActiveCell.Offset(0, 17).Value
    End Sub
    Private Sub cmdAdd_Click()
    Set ws = Sheet26
      '''find  first empty row in database
      ''iRow = ws.Cells(Rows.Count, 1) .End(xlUp).Offset(1, 0).Row
       'revised code to avoid problems with Excel tables in newer versions
    iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    'check for a part number
    If Trim(Me.recnum.Value) = "" Then
      Me.recnum.SetFocus
      'MsgBox "Please enter an ID Number; one will be suggested…"
      recnum.Value = Format(Application.Max(ws.Range("A:A")) + 1, "000")
      Exit Sub
     'Test for blank entry
    ElseIf issuer.Value = "" Then
        MsgBox "Please select the Issuer", vbExclamation, "Sunrise Transport, Inc."
        Exit Sub
    ElseIf driver.Value = "" Then
        MsgBox "Please select the Driver"
        Exit Sub
    ElseIf so1.Value = "" Then
        MsgBox "Please enter a valid Sales Order Number"
        Exit Sub
    ElseIf location.Value = "" Then
        MsgBox "Please select the Location"
        Exit Sub
    ElseIf purpose.Value = "" Then
        MsgBox "Please select the Purpose"
        Exit Sub
    ElseIf checkno.Value = "" Then
        MsgBox "Please enter a Check Number"
        Exit Sub
    ElseIf expresscode.Value = "" Then
        MsgBox "Please enter a valid Express Code in the following format: ##### #### OR ##### #### ####"
        Exit Sub
        End If
         'Prompt user before adding record
        MsgBox "Add transaction?", vbOKOnly
         ' Find emtpy row
        lrow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
         'Add data to worksheet
        ws.Cells(lrow, "A") = recnum.Value
        ws.Cells(lrow, "B") = issuer.Value
        ws.Cells(lrow, "C") = driver.Value
        ws.Cells(lrow, "D") = so1.Value
        ws.Cells(lrow, "E") = so2.Value
        ws.Cells(lrow, "F") = so3.Value
        ws.Cells(lrow, "G") = so4.Value
        ws.Cells(lrow, "H") = so5.Value
        ws.Cells(lrow, "I") = so6.Value
        ws.Cells(lrow, "J") = so7.Value
        ws.Cells(lrow, "K") = so8.Value
        ws.Cells(lrow, "L") = so9.Value
        ws.Cells(lrow, "M") = so10.Value
        ws.Cells(lrow, "N") = location.Value
        ws.Cells(lrow, "O") = purpose.Value
        ws.Cells(lrow, "P") = checkno.Value
        ws.Cells(lrow, "Q") = expresscode.Value
        ws.Cells(lrow, "R") = remarks.Value
        Unload cdatafrm
        cdatafrm.Show
        End Sub
    Private Sub so1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        If so1.Value = "BH" Then
        Exit Sub
        ElseIf Len(so1.Value) <> 7 Then
        MsgBox "Please enter a 7 digit number"
        Cancel = True
        Exit Sub
        End If
     End Sub
    Private Sub checkno_Exit(ByVal Cancel As MSForms.ReturnBoolean)
       If Len(checkno.Value) <> 10 Then
        MsgBox "Please enter a valid 10 digit Check Number"
        Cancel = True
        Exit Sub
        End If
     End Sub
    Private Sub expresscode_Exit(ByVal Cancel As MSForms.ReturnBoolean)
     Select Case Len(expresscode.Text)
       Case 9
         expresscode.Text = Format(expresscode.Text, "84271 ##### ####")
       Case 13
         expresscode.Text = Format(expresscode.Text, "84271 ##### #### ####")
       Case 16, 21
       Case Else
         Cancel = True
         MsgBox "Please enter a 9 or 13 digit number"
     End Select
     End Sub
    Private Sub cmdClear_Click()
        Dim ctl As MSForms.Control
        For Each ctl In Me.Controls
            Select Case TypeName(ctl)
                Case "TextBox"
                    ctl.Text = ""
                Case "CheckBox", "OptionButton", "ToggleButton"
                    ctl.Value = False
                Case "ComboBox", "ListBox"
                    ctl.ListIndex = -1
            End Select
        Next ctl
    End Sub
    Private Sub cmdQuit_Click()
     Dim ctl As MSForms.Control
        For Each ctl In Me.Controls
            Select Case TypeName(ctl)
                Case "TextBox"
                    ctl.Text = ""
                Case "CheckBox", "OptionButton", "ToggleButton"
                    ctl.Value = False
                Case "ComboBox", "ListBox"
                    ctl.ListIndex = -1
            End Select
        Next ctl
      Unload cdatafrm
     End Sub
    Private Sub SpinButton1_SpinDown()
    If Me.recnum.Value = "1" Then
    MsgBox "First Transaction Available"
    Exit Sub
    End If
    Me.recnum.Value = Worksheets("Comdata Entry").Range("A" & Me.SpinButton1.Value).Value
    Me.issuer.Value = Worksheets("Comdata Entry").Range("B" & Me.SpinButton1.Value).Value
    Me.driver.Value = Worksheets("Comdata Entry").Range("C" & Me.SpinButton1.Value).Value
    Me.so1.Value = Worksheets("Comdata Entry").Range("D" & Me.SpinButton1.Value).Value
    Me.so2.Value = Worksheets("Comdata Entry").Range("E" & Me.SpinButton1.Value).Value
    Me.so3.Value = Worksheets("Comdata Entry").Range("F" & Me.SpinButton1.Value).Value
    Me.so4.Value = Worksheets("Comdata Entry").Range("G" & Me.SpinButton1.Value).Value
    Me.so5.Value = Worksheets("Comdata Entry").Range("H" & Me.SpinButton1.Value).Value
    Me.so6.Value = Worksheets("Comdata Entry").Range("I" & Me.SpinButton1.Value).Value
    Me.so7.Value = Worksheets("Comdata Entry").Range("J" & Me.SpinButton1.Value).Value
    Me.so8.Value = Worksheets("Comdata Entry").Range("K" & Me.SpinButton1.Value).Value
    Me.so9.Value = Worksheets("Comdata Entry").Range("L" & Me.SpinButton1.Value).Value
    Me.so10.Value = Worksheets("Comdata Entry").Range("M" & Me.SpinButton1.Value).Value
    Me.location.Value = Worksheets("Comdata Entry").Range("N" & Me.SpinButton1.Value).Value
    Me.purpose.Value = Worksheets("Comdata Entry").Range("O" & Me.SpinButton1.Value).Value
    Me.checkno.Value = Worksheets("Comdata Entry").Range("P" & Me.SpinButton1.Value).Value
    Me.expresscode.Value = Worksheets("Comdata Entry").Range("Q" & Me.SpinButton1.Value).Value
    Me.remarks.Value = Worksheets("Comdata Entry").Range("R" & Me.SpinButton1.Value).Value
    End Sub
    Private Sub SpinButton1_SpinUp()
    Let recnum.Value = SpinButton1.Visible
    Me.recnum.Value = Worksheets("Comdata Entry").Range("A" & Me.SpinButton1.Value).Value
    Me.issuer.Value = Worksheets("Comdata Entry").Range("B" & Me.SpinButton1.Value).Value
    Me.driver.Value = Worksheets("Comdata Entry").Range("C" & Me.SpinButton1.Value).Value
    Me.so1.Value = Worksheets("Comdata Entry").Range("D" & Me.SpinButton1.Value).Value
    Me.so2.Value = Worksheets("Comdata Entry").Range("E" & Me.SpinButton1.Value).Value
    Me.so3.Value = Worksheets("Comdata Entry").Range("F" & Me.SpinButton1.Value).Value
    Me.so4.Value = Worksheets("Comdata Entry").Range("G" & Me.SpinButton1.Value).Value
    Me.so5.Value = Worksheets("Comdata Entry").Range("H" & Me.SpinButton1.Value).Value
    Me.so6.Value = Worksheets("Comdata Entry").Range("I" & Me.SpinButton1.Value).Value
    Me.so7.Value = Worksheets("Comdata Entry").Range("J" & Me.SpinButton1.Value).Value
    Me.so8.Value = Worksheets("Comdata Entry").Range("K" & Me.SpinButton1.Value).Value
    Me.so9.Value = Worksheets("Comdata Entry").Range("L" & Me.SpinButton1.Value).Value
    Me.so10.Value = Worksheets("Comdata Entry").Range("M" & Me.SpinButton1.Value).Value
    Me.location.Value = Worksheets("Comdata Entry").Range("N" & Me.SpinButton1.Value).Value
    Me.purpose.Value = Worksheets("Comdata Entry").Range("O" & Me.SpinButton1.Value).Value
    Me.checkno.Value = Worksheets("Comdata Entry").Range("P" & Me.SpinButton1.Value).Value
    Me.expresscode.Value = Worksheets("Comdata Entry").Range("Q" & Me.SpinButton1.Value).Value
    Me.remarks.Value = Worksheets("Comdata Entry").Range("R" & Me.SpinButton1.Value).Value
    If Me.recnum.Value = "" Then
    MsgBox "Last Transaction Available"
    Exit Sub
    End If
    End Sub
    Private Sub UserForm_QueryClose(Cancel As Integer, _
      CloseMode As Integer)
      If CloseMode = vbFormControlMenu Then
        Cancel = True
        MsgBox "To Exit this application, please use the 'Quit' button."
      End If
    End Sub
    Private Sub cmdUpdate_Click()
        Dim CurRow As Integer
        Dim lrow As Long
        lrow = ActiveCell.Row
        Dim ws As Worksheet
        Set ws = Worksheets("Comdata Entry")
    If issuer.Value = "" Then
        MsgBox "Please select the Issuer", vbExclamation, "Sunrise Transport, Inc."
        Exit Sub
    ElseIf driver.Value = "" Then
        MsgBox "Please select the Driver"
        Exit Sub
    ElseIf so1.Value = "" Then
        MsgBox "Please enter a valid Sales Order Number"
        Exit Sub
    ElseIf location.Value = "" Then
        MsgBox "Please select the Location"
        Exit Sub
    ElseIf purpose.Value = "" Then
        MsgBox "Please select the Purpose"
        Exit Sub
    ElseIf checkno.Value = "" Then
        MsgBox "Please enter a Check Number"
        Exit Sub
    ElseIf expresscode.Value = "" Then
        MsgBox "Please enter a valid Express Code in the following format: ##### #### OR ##### #### ####"
        Exit Sub
        End If
       'Update data to worksheet
        ws.Cells(lrow, 1).Value = Me.recnum.Value
        ws.Cells(lrow, 2).Value = Me.issuer.Value
        ws.Cells(lrow, 3).Value = Me.driver.Value
        ws.Cells(lrow, 4).Value = Me.so1.Value
        ws.Cells(lrow, 5).Value = Me.so2.Value
        ws.Cells(lrow, 6).Value = Me.so3.Value
        ws.Cells(lrow, 7).Value = Me.so4.Value
        ws.Cells(lrow, 8).Value = Me.so5.Value
        ws.Cells(lrow, 9).Value = Me.so6.Value
        ws.Cells(lrow, 10).Value = Me.so7.Value
        ws.Cells(lrow, 11).Value = Me.so8.Value
        ws.Cells(lrow, 12).Value = Me.so9.Value
        ws.Cells(lrow, 13).Value = Me.so10.Value
        ws.Cells(lrow, 14).Value = Me.location.Value
        ws.Cells(lrow, 15).Value = Me.purpose.Value
        ws.Cells(lrow, 16).Value = Me.checkno.Value
        ws.Cells(lrow, 17).Value = Me.expresscode.Value
        ws.Cells(lrow, 18).Value = Me.remarks.Value
        ActiveWorkbook.Save
    End Sub

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Spin Down Event skipping one record

    Check that the SmallChange property for SpinButton1 is set to 1 and not 2.

  6. #6
    Registered User
    Join Date
    07-31-2014
    Location
    Ephrata, PA
    MS-Off Ver
    2007
    Posts
    7

    Re: Spin Down Event skipping one record

    Yes it is.

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Spin Down Event skipping one record

    Can you attach your workbook file?

  8. #8
    Registered User
    Join Date
    07-31-2014
    Location
    Ephrata, PA
    MS-Off Ver
    2007
    Posts
    7

    Re: Spin Down Event skipping one record

    Workbook attached.
    Attached Files Attached Files

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Spin Down Event skipping one record

    Your workbook functions as expected for me. The spinbutton shifts one record at a time.

    I'm wondering if your mouse is somehow double clicking or sending clicks too fast.

    As a test: with the spinbutton control active, use the keyboard up\down arrows to change records. Does that make a difference?

    Another test: increase the spinbutton .Delay property to say 200 or more. Does that make a difference?

  10. #10
    Registered User
    Join Date
    07-31-2014
    Location
    Ephrata, PA
    MS-Off Ver
    2007
    Posts
    7

    Re: Spin Down Event skipping one record

    I pushed the delay up to 5,000. I also tried using the keyboard vs. the mouse. Still opens to record 7, and when spin down is pressed or selected jumps to record 5. If spin up is selected next, it does go to record 6. Weird. I'm going to try it on another computer. Thanks.

+ 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. Spin button event handling
    By d3hartm2 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-17-2014, 05:29 PM
  2. Auto sort macro for spin button event
    By mantooth29 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-05-2011, 02:58 PM
  3. Record Time & Date of Event
    By R_S_6 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-18-2009, 07:27 PM
  4. Spin Button Event Change
    By sepandb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2008, 04:00 PM
  5. Spin Button:spin cells A7
    By ice in forum Excel General
    Replies: 1
    Last Post: 03-16-2007, 02:23 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