Advertisement

07.30.2008 at 12:41PM PDT, ID: 23608698
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

creating dynamic search form/sql query... (BuildCriteria)

Asked by NO_CARRIER in Access Coding/Macros, Microsoft Access Database, Access Forms

I'm creating a Search form which has the various fields from the database/tables in it.  I'm using the same code/example provided in help.

However, the code only explains how to cycle through Textbox controls.  I have some checkbox controls (and Yes/No options in the tables) that I would like to search for as well.  (i.e. return records where the checkbox is enabled.)

Here's the code I'm using, and the checkbox attempt I've made... but it's not working.  Crashed on the first line of the BuildCriteria function.. :(

   Dim ctl As Control
    Dim sSQL As String
    Dim sWhereClause As String
    Dim sGroupClause As String
   
    'Initialize the Where Clause variable.
    sWhereClause = " Where "
    sGroupClause = " GROUP BY tblMain.[Client Name]...."
   
    'Start the first part of the select statement.
    sSQL = "SELECT tblMain.ID.... FROM ... "
 
'Loop through each control on the form to get its value.
    For Each ctl In Me.Controls
        With ctl
            'The only Control you are using is the text box.
            'However, you can add as many types of controls as you want.
            Select Case .ControlType
                Case acTextBox
                    .SetFocus
                    'This is the function that actually builds
                    'the clause.
                    If sWhereClause = " Where " Then
                        sWhereClause = sWhereClause & BuildExpression(.Name, dbText, .Text)
                    Else
                        sWhereClause = sWhereClause & " and " & BuildExpression(.Name, dbText, .Text)
                    End If
                Case acComboBox
                    .SetFocus
                    'This is the function that actually builds
                    'the clause.
                    If sWhereClause = " Where " Then
                        sWhereClause = sWhereClause & BuildExpression(.Name, dbByte, .Value)
                    Else
                        sWhereClause = sWhereClause & " and " & BuildExpression(.Name, dbByte, .Value)
                    End If
                   
                Case acCheckBox
                    .SetFocus
                    'This is the function that actually builds
                    'the clause.
                    If .Value = -1 Then
                        If sWhereClause = " Where " Then
                            sWhereClause = sWhereClause & BuildCriteria(.Name, dbByte, .Text)
                            MsgBox "!"
                        Else
                            sWhereClause = sWhereClause & " and " & BuildCriteria(.Name, dbByte, .Text)
                            MsgBox "!!"
                        End If
                    Else
                    End If
            End Select
        End With
    Next ctl
Public Function BuildExpression(pstrField As String, _
                                ptypFieldType As DataTypeEnum, _
                                pstrExpression As String) As String
 
    BuildExpression = BuildCriteria(pstrField, ptypFieldType, pstrExpression)
    If ptypFieldType = dbText Then
        BuildExpression = Replace(BuildExpression, "=", " Like ")
        BuildExpression = Replace(BuildExpression, pstrExpression, "*" & pstrExpression & "*")
    End If
End Function

Start Free Trial
 
Loading Advertisement...
 
[+][-]07.30.2008 at 01:06PM PDT, ID: 22124252

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.13.2008 at 06:01AM PDT, ID: 22221270

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.20.2008 at 11:06AM PDT, ID: 22272300

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Access Coding/Macros, Microsoft Access Database, Access Forms
Sign Up Now!
Solution Provided By: eghtebas
Participating Experts: 1
Solution Grade: A
 
 
[+][-]09.13.2008 at 05:42PM PDT, ID: 22470642

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628