Hi there,
I've been working on a database for a Dutch nursing home, but I'm struggling to get it to work. The file provides for a userform that enables users to search for residents and retrieve their appartmentnumber and the adress of their legal representative. This userform consists of three parts; in the first, the user can type the full or partial name of the resident of interest in a textbox; in the second phase, all matching registrations are presented in a listbox; and in the third phase, a macro searches for the name selected in the listbox and retrieves the corresponding appartmentnumber and adress. The first two phases of the userform work fine, but in the third phase, the macro fails to find any matches even though it is practically the same as the macro used in phase 1. I'd greatly appreciate it if anyone would take a look at the attached file and help me out here. Thanks in advance.
Last edited by WCJanssen; 07-05-2009 at 04:28 AM.
Hey WCJanssen
the search doesn't works because of the way you fill the list box with the code below
You are adding a space " " before the value so when you search using the selected item it's looking for value a space in front and so the search fails.Code:Private Function CvtRowValues(rowNumber As Long) As String Dim column As Integer CvtRowValues = "" For column = 1 To 1 CvtRowValues = CvtRowValues & " " & Cells(rowNumber, column).Value Next End Function
You do not need For Next Loop in this case. Simply put
You probably do not even need another private function. you can use your additem line asCode:Private Function CvtRowValues(rowNumber As Long) As String Dim column As Integer CvtRowValues = "" CvtRowValues = Cells(rowNumber, column).Value End Function
Another thing I noticed is that you do not need any of your Do While Loops, unless you posted a simplified version of your spreadsheet.Code:ListBoxSpec.AddItem Cells(vFound.Row, 1).Value
Now for whatever reason if you want leave the space you can use LTrim(ListBoxSpec.Value) function under your Find statement for it to work.
Hope this helps.
thanks a lot! I've replaced the function for the line you suggested and it works perfect.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks