+ Reply to Thread
Results 1 to 6 of 6

Userform selection yields wrong information

Hybrid View

  1. #1
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Userform selection yields wrong information

    So your problem is using a non-unique value for your search. I made a few changes. Your listbox did not specify the width for the last column, so I set it to 80, and added another 0 width column.

    ColumnWidth property for lstLookup now reads: 100 pt;60 pt;40 pt;80 pt;70 pt;80 pt;0 pt
    Then I added one line to your search button code:

                    If rngFind.Row > 1 Then
                        lstLookup.AddItem rngFind.Value
                        lstLookup.List(lstLookup.ListCount - 1, 1) = rngFind.Offset(0, 1)
                        lstLookup.List(lstLookup.ListCount - 1, 2) = rngFind.Offset(0, 8)
                        lstLookup.List(lstLookup.ListCount - 1, 3) = rngFind.Offset(0, 2)
                        lstLookup.List(lstLookup.ListCount - 1, 4) = rngFind.Offset(0, 4)
                        lstLookup.List(lstLookup.ListCount - 1, 5) = rngFind.Offset(0, 7)
                        lstLookup.List(lstLookup.ListCount - 1, 6) = rngFind.Row
                    End If
    This means that now you have the row number of the search results available to do your textbox updating. Which requires a change to the double-click event for your listbox (changed it as little as possible):

    Private Sub lstLookup_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    'declare the variables
        Dim cPayroll As Integer
        Dim i As Integer
        Dim findvalue
        'error block
        On Error GoTo errHandler:
        'get the select value from the listbox
        For i = 0 To lstLookup.ListCount - 1
            If lstLookup.Selected(i) = True Then
                cPayroll = lstLookup.List(i, 6)
            End If
        Next i
        'find the payroll number
        Set findvalue = Sheet11.Range("A" & cPayroll)
        'add the database values to the userform
        cNum = 19
        For x = 1 To cNum
            Me.Controls("Reg" & x).Value = findvalue
     
            Set findvalue = findvalue.Offset(0, 1)
        Next
        'disable adding
        Me.cmdAdd.Enabled = False
        Me.cmdEdit.Enabled = True
        
        ' deal with textbox formatting issue
        Reg6.Value = Format(Reg6.Value, "h:mm AM/PM")
        
        'error block
        On Error GoTo 0
        Exit Sub
    errHandler::
        MsgBox "An Error has Occurred  " & vbCrLf & "The error number is:  " _
               & Err.Number & vbCrLf & Err.Description & vbCrLf & _
               "Please notify the administrator"
               
               
    End Sub
    Last edited by Arkadi; 04-30-2019 at 09:17 AM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  2. #2
    Forum Contributor
    Join Date
    07-30-2017
    Location
    texas
    MS-Off Ver
    2016
    Posts
    123

    Re: Userform selection yields wrong information

    Beautiful solution. I just did not have the smarts to do it. That is why I lean on the "Gurus" to teach me. Thanks for all your help!

+ 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. Get Multi Selection Listbox userform and clear all selection
    By jp16 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-30-2018, 10:43 AM
  2. [SOLVED] Userform ComboBox selection not displaying on first attempted selection
    By yachrishere in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 11-01-2016, 07:44 PM
  3. UserForm ComboBox selection to activate WorkSheet selection row.
    By excelV3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-24-2015, 12:35 PM
  4. [SOLVED] Filtering more information via criteria selection on userform
    By nikadon in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-21-2013, 09:35 PM
  5. [SOLVED] Userform Combobox selection populates wrong data in the textboxes
    By yahya263 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-02-2013, 09:46 AM
  6. Userform that duplicates Information and places in correct sheet depending on selection
    By ExcelHacks_99 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-18-2013, 03:38 PM
  7. auto sum yields wrong number
    By Jeroen1000 in forum Excel General
    Replies: 5
    Last Post: 10-19-2009, 05:59 AM

Tags for this Thread

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