Problems with Search

mercury

Registered User.
Local time
Today, 00:59
Joined
Jul 17, 2004
Messages
35
Hi everyone

Im not sure whether i should post my question here in the form forum or in the report,anyway im using a form to act as a search page, where a user would be able to type a Company Name in a text box then they would have to click a button which would open a report showing only the Company's information that you searched on i used the following code but i keep getting all the Companies that are in the database, Any ideas on how i could rectify this problem ?

Code:
Dim pstrCriteria As String
    If IsNull([txtSearch]) Then
        MsgBox " Please enter search criteria"
    Else
        'If legal Company Name entered, form criteria, and print
        If txtSearch <> " " Then
            strCriteria = txtSearch
            DoCmd.OpenReport "rptIndivdualSearch", acViewPreview, , pstrCriteria
      
        End If
    End If
 
First of all, I believe you have a typo because you have string names of strCriteria and pstrCriteria...

In the strCriteria, you have to specify the field name that you want to filter by such as:

strCriteria = "[CompanyName] = " & Chr$(34) & txtSearch & Chr$(34)
 
Hi

Thanks alot that worked but what exactly is does

"[CompanyName] = " & Chr$(34) & txtSearch & Chr$(34) mean?

Mercury
 
Chr$(34) is the ASCII character code for quotations so in essence, that line of code is building a string. So if the user enters Microsoft your strCriteria would look like

[CompanyName] = "Microsoft"
 
Why not have a command button on your form run a query and then base the report on the query results?
 

Users who are viewing this thread

Back
Top Bottom