Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Finding records in a DGrid using parameters from access table

Posted on 2002-07-20
4
167 Views
Last Modified: 2010-05-02
I am a kenyan who is new in vb, and i have had this particular problem. I want to connect to an access table with parameters and allow the  user to find records by entering His/her paramerters from  a form.
Just how can I do that?
(SOME CODE MIGHT HELP)
NOTE: I AM USING ADO CODE.
0
Comment
Question by:sammyquest85
  • 2
4 Comments
 

Expert Comment

by:paulll
ID: 7168327
I'm not clear on the question but it sounds like you just need to know when criteria is specified.

Example:
A form that has searching on customer, city and state.

The form would have text boxes TxtCustomer, TxtCity and TxtState.

When user presses an OK button to do the search, use the following code.

Dim SqlString as String, ValType as String, temp as String

SqlString = "SELECT * FROM TableName WHERE Customer IS NOT NULL"
If Len(TxtCustomer) Then
    temp = TxtCustomer
    ValType = GetValType(temp)
    SqlString = SqlString & " AND Customer ValType '" & TxtCustomer & "'"
End If
If Len(TxtCity) Then
    temp = TxtCity
    ValType = GetValType(temp)
    SqlString = SqlString & " AND City ValType '" & TxtCity & "'"
End If
If Len(TxtState) Then
    temp = TxtState
    ValType = GetValType(temp)
    SqlString = SqlString & " AND State ValType '" & TxtState & "'"
End If

You could also do date ranges using the "BETWEEN" reserved word for 2 text boxes.

Function GetValType(ByVal temp As String) As String
'You could use a check box with a value of 1 to do searches of "LIKE" and
'put your own percent signs before and after the values in the text box criteria
If Instr(temp, "%") Then
    GetValType = "LIKE"
Else
    GetValType = "="
End If
End Function

0
 

Accepted Solution

by:
paulll earned 50 total points
ID: 7168331
A mistake in above code
It should be SqlString = SQLString & " AND FieldName " & ValType & "'" & temp & "'"
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8031899
Hi sammyquest85,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept paulll's comment(s) as an answer.

sammyquest85, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 8095543
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question