Consulting

Results 1 to 3 of 3

Thread: Database search and return of results

  1. #1
    VBAX Regular
    Joined
    Jan 2008
    Posts
    7
    Location

    Database search and return of results

    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:

    [VBA]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
    [/VBA]

    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!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this

    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jan 2008
    Posts
    7
    Location
    Working!

    Thanks a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •