Google Answers Logo
View Question
 
Q: VB6 Find Record? ( No Answer,   2 Comments )
Question  
Subject: VB6 Find Record?
Category: Computers > Programming
Asked by: jstm-ga
List Price: $10.00
Posted: 14 Mar 2005 19:02 PST
Expires: 13 Apr 2005 20:02 PDT
Question ID: 494784
Is there a way to put a find record on a VB6 form like in Access?
Answer  
There is no answer at this time.

Comments  
Subject: Re: VB6 Find Record?
From: frde-ga on 15 Mar 2005 04:51 PST
 
Why don't you ask in a VB News Group ?
Subject: Re: VB6 Find Record?
From: willcodeforfood-ga on 15 Mar 2005 13:07 PST
 
You are straying into areas where Access shines and VB takes more work
to accomplish the same things.  If you want to the user to be able to
submit search parameters and get back a list of matching records,
you've got to do all the hard work yourself.

1. Create a series of controls where the user can enter their search
parameters and a listbox to put the possible matches in.
2. When the user presses the search button, you parse the search
values that the user entered into a SQL statement.
3. Run the SQL statement and put the results of the query into the listbox.

dim sql, select, where, orderby as String
select = "select field1, field2, field3 from sometable "
orderby = "order by field2 "
' if user put something in txtFieldA textbox, use that to filter against table
If Len(txtFieldA) > 0 Then
    If Len(where) > 0 Then
        where = where & " and "
    Else
        where = " where "
    End if
    where = where & "FieldA='" & txtFieldA & "'"  ' FieldA is text or date
End If
' if user put something in txtFieldB textbox, use that to filter against table
If Len(txtFieldB) > 0 Then
    If Len(where) > 0 Then
        where = where & " and "
    Else
        where = " where "
    End if
    where = where & "FieldB=" & txtFieldB   ' FieldB is numeric
End If

' ...continue to build the query for all the other filter (parameter) fields

sql = select & where & orderby ' put the sql statement together

' open the query using a Recordset
rs.Open sql, mconAP, adOpenKeyset, adLockOptimistic, adCmdText

' put the results into a listbox
rs.MoveFirst
List1.Clear
While not rs.EOF
    List1.AddItem (rs("Field1") & " - " & rs("Field2"))
    rs.MoveNext
Wend

You may want to find a good aftermarket datagrid ActiveX component for
displaying data, rather than the listbox control.  Some datagrids are
very powerful and do a lot of work for you, much like Access forms do.

It may also be worthwhile about now to teach yourself a little bit
about SQL Server stored procedures.  Most DBAs would cringe if they
saw the code I just wrote, because it uses what is known as "inline
SQL."  As an application grows, you won't want bits and pieces of SQL
statements scattered throughout your code.  It's easier to centrally
manage your application if it just calls stored procedures in the
database, rather than parsing its own SQL statements.  Some inline SQL
is unavoidable, but stored procedures will make your software more
portable, powerful and manageable.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy