|
Access 2000 Tabular Form - Building a Query Command Function
|
Email
|
| Submitted on: |
8/23/2002 3:51:40 PM |
| By: |
davepamn
|
| Level: |
Beginner |
| User Rating: |
By 2 Users |
| Compatibility: |
SQL Server 2000, SQL Server 7.0, SQL Server 6.5 and earlier, Other |
| Views: |
15800 |
|
(About the author) |
|
|
|
Overview: Suppose you have an Access 2000 tabular form,
meaning each row is a record. Suppose you want
to have the ability to input filter criteria from the form
and press a query button for the filter to apply. This
article explains how to create this functionality.
|
| |
Terms of Agreement:
By using this article, you agree to the following terms...
- You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
- You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
- You may link to this article from another website, but ONLY if it is not wrapped in a frame.
- You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
|
Building a Query Command
David Nishimoto
davepamn@relia.net
Article: Building a Query Command Function:
Overview: Suppose you have an Access2000 tabular form,
meaning each row is a record.Suppose you want
to have the ability to input filter criteria from the form
and press a query button for the filter to apply. This
article explains how to create this functionality.
The Filter has four textbox called: txtFirstName,
txtMiddleInitial, txtLastName, and txtSSN. The
datbase table "member" has corresponding fields
called First, Mi,Last, and SSN.
The AttachAnd function is used to create the
SQL filter string: "First='David' and Last='Nishimoto'"
Option Compare Database
Dim ssql
1. User pressed the Query button
2. Or you could catch a textbox on exit event
Private Sub cmdQuery_Click()
BuildQueryCommand
End Sub
1. BuildQueryCommand builds an filter critera by receiving the fieldname and critiera.
2. The filter criteria is applied
Private Function BuildQueryCommand()
sSQL = ""
Call AttachAnd("First", "'" & txtFirstName & "'")
Call AttachAnd("Mi", "'" & txtMiddleInitial & "'")
Call AttachAnd("Last", "'" & txtLastName & "'")
Call AttachAnd("SSN", "'" & txtSSN & "'")
Filter = sSQL
FilterOn = True
End Function
1. Check for single or multiple criteria
Single: "first='David'"
Multiple:"First='David' and Last='Nishimoto'"
Private Function AttachAnd(sField, sValue)
If sValue = "''" Or sValue = "" Then
Exit Function
End If
If Occurances(sSQL, "=") = 0 Then
sSQL = sSQL & sField & "=" & sValue
Else
sSQL = sSQL & " and " & sField & "=" & sValue
End If
End Function
1. Count the occurances for a pattern in the sql
phrase
Private Function Occurances(sSQL, sOperator)
Dim offset
Dim iCount
offset = 1
While offset <> 0
offset = InStr(offset + 1, sSQL, sOperator)
If offset > 1 Then
iCount = iCount + 1
End If
Wend
Occurances = iCount
End Function
|
|
Other 9 submission(s) by this author
|
|
Report Bad Submission
|
Your Vote
|
| |
Other User Comments
|
9/19/2002 1:54:29 PM:
HI U helped me alot in my recent project this code if usefull for me keep up the good works ! I need to talk to About query in VB6 can u email me at ebayhackwu@yahoo.com thanks i'lll reply to u soon as posible i really need your help (If this comment was disrespectful, please report it.)
|
4/29/2004 10:01:06 PM:
it great (If this comment was disrespectful, please report it.)
|
7/24/2009 4:09:29 AM: manas
grt (If this comment was disrespectful, please report it.)
|
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)
To post feedback, first please login.
|