PDA

View Full Version : Database search and return of results



mirko
03-14-2008, 01:56 PM
Hi guys,

I have a problem and I would appreciate it if you could help me.

I have a database of clients and transactions and I want to do a search by client name and I want all the transactions by the specific client returned in a form.
I currently have a form which asks for the client name and then another form with a listbox on which I want the transactions to be populated. This is the code I have for the form where I want the transactions to be populated:

Private Sub UserForm_Initialize()

Dim nRecords As Integer
' Populate the listbox.
With LstSelectSurvey
With Worksheets("PropSurveys").Range("A1")
nRecords = Range(.Offset(1, 0), .End(xlDown)).Rows.Count

For i = 1 To nRecords

If .Offset(i, 0).Value = FrmSrcbyClientName.TxtClient Then
.AddItem Worksheets("PropSurveys").Range("A1").Offset(i, 0)
End If
Next
End With
End With

End Sub


FrmSrcbyClientName.TxtClient is the name I am searching for and is generated from the previous form where I do the search.

This code gives me the following error "Object does not support this property or method"

Any ideas on how to tackle this? Thanks in advance for the help!

Bob Phillips
03-14-2008, 02:19 PM
Try this



Private Sub UserForm_Initialize()
Dim sh As Worksheet
Dim nRecords As Integer

Set sh = Worksheets("PropSurveys")
' Populate the listbox.
With LstSelectSurvey
nRecords = sh.Range(sh.Range("A1").Offset(1, 0), sh.Range("A1").End(xlDown)).Rows.Count

For i = 1 To nRecords

If sh.Range("A1").Offset(i, 0).Value = FrmSrcbyClientName.TxtClient Then
.AddItem Worksheets("PropSurveys").Range("A1").Offset(i, 0)
End If
Next
End With

End Sub

mirko
03-14-2008, 02:27 PM
Working!

Thanks a lot:)