Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

BuildCriteria

Posted on 2000-02-18
3
Medium Priority
?
458 Views
Last Modified: 2008-03-03
I'm running a popup box that allows the user to enter some criteria to filter out a form...The problem is with strInput1 and strInput2. If the user doesn't input anything in this field then I want the BuildCriteria to run the command with the following
Like "*" or is null
I've left the latest concatenation in for example purposes..

Dim frm As Form
    Dim strInput As String, strFilter As String, strInput2 As String, strinput3 As String

    Dim rs As Recordset
   
    Set frm = Forms!frmBasePlanMain
     
            If IsNull(Forms!frmBasePlanMainSearch!TxtSiteName) Then
                MsgBox "You Must Enter a Site Name"
                Exit Sub
            Else
            strInput = Forms!frmBasePlanMainSearch!TxtSiteName
            End If
           
            If IsNull(Forms!frmBasePlanMainSearch!txtExchUnit) Then
                strInput2 = "*" & "' or is null '"
            Else
            strInput2 = Forms!frmBasePlanMainSearch!txtExchUnit
            End If
           
            If IsNull(Forms!frmBasePlanMainSearch!txtExchExt) Then
                strinput3 = "*" & "' or is null '"
            Else
            strinput3 = Forms!frmBasePlanMainSearch!txtExchExt
            End If
           
        strFilter = BuildCriteria("exchname", dbText, strInput)
        strFilter = strFilter & " AND " & BuildCriteria("ExchUnit", dbText, strInput2)
        strFilter = strFilter & " AND " & BuildCriteria("ExchExt", dbText, strinput3)
       
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM BasePlan WHERE " & strFilter, dbOpenSnapshot)
   
    If Not rs.EOF Then
        frm.Filter = strFilter
        frm.FilterOn = True
        frm.OrderBy = "apack DESC"
        frm.OrderByOn = True
        rs.Close
    Else
         MsgBox "No Records Returned"
         rs.Close
    End If

Any help??

Scottsanoedro
0
Comment
Question by:scottsanpedro
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
paasky earned 200 total points
ID: 2535096
Hello scottsanpedro,

Try this:

....
    Set frm = Forms!frmBasePlanMain
     
            If IsNull(Forms!frmBasePlanMainSearch!TxtSiteName) Then
                MsgBox "You Must Enter a Site Name"
                Exit Sub
            Else
            strInput = Forms!frmBasePlanMainSearch!TxtSiteName
            End If
           
            strFilter = BuildCriteria("exchname", dbText, strInput)
             
            If Not IsNull(Forms!frmBasePlanMainSearch!txtExchUnit) Then
                strFilter = strFilter & " AND " & BuildCriteria("ExchUnit", dbText, strInput2)
            End If
             
            If Not IsNull(Forms!frmBasePlanMainSearch!txtExchExt) Then
                strFilter = strFilter & " AND " & BuildCriteria("ExchExt", dbText, strinput3)
            End If
       
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM BasePlan WHERE " & strFilter, dbOpenSnapshot)
....
....
     
Regards,
Paasky
0
 
LVL 1

Author Comment

by:scottsanpedro
ID: 2535124
Of course...

Thanks very much

How it should be..Nice and quick

Cheers

Scott
0
 
LVL 1

Author Comment

by:scottsanpedro
ID: 2535128
Cheers

Scott
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

877 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