Combo Box Search Criteria

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nebula53
    New Member
    • Aug 2010
    • 32

    Combo Box Search Criteria

    I have Combo box Titled ( Contract Status) Contains 4 values ( Active, Closed, Canceled, released)

    I need when I chose form the Drop down list one of the status to run report with all contracts with that specific status.

    All the Data are coming from one table contains 9 columns one of them are the ( Status)
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1290

    #2
    Nebbie,
    I assume you have a button to launch the report. In the click event of that button you will have code like this:

    Code:
    dim strCriteria as string
    dim strReportName as string
    
    strcriteria = "[Status]='" & me!ContractStatus & "'"
    strReportName = "name of the report"
    
    docmd.openreport strReportName , acPreview , strCriteria
    or
    docmd.openreport strReportName , acViewNormal
    That should do it.

    Jim

    Comment

    • nebula53
      New Member
      • Aug 2010
      • 32

      #3
      Unfortunately I tried it but it’s not working

      Comment

      • colintis
        Contributor
        • Mar 2010
        • 255

        #4
        Have you correctly set up the report's control source?

        Comment

        • nebula53
          New Member
          • Aug 2010
          • 32

          #5
          Private Sub Command141_Clic k()

          Dim strCriteria As String
          Dim strReportName As String

          strCriteria = "[Status]='" & Me!ContractStat us & "'"
          strReportName = "PMCONTRACT S"

          DoCmd.OpenRepor t PMCONTRACTS, acViewNormal

          End Sub

          the error is ( 2465 : Microsoft office can't find the field ' ContractsStstus ' referred to in your expression

          Comment

          • colintis
            Contributor
            • Mar 2010
            • 255

            #6
            Check back and see what's your combo box actually named in the form. Or try use the Me.ContractStat us instead of Me!ContractStat us

            Comment

            • semanticnotion
              New Member
              • Sep 2010
              • 66

              #7
              The message you have entered is too short. Please lengthen your message to at least 1

              whats this problem is.....
              i cant post my question.

              Comment

              • semanticnotion
                New Member
                • Sep 2010
                • 66

                #8
                sorry for reply here
                but what this problem tells when i post my question "The message you have entered is too short. Please lengthen your message to at least 1"

                i cant post my question even cant edit the above reply. its a test post.

                Comment

                • nebula53
                  New Member
                  • Aug 2010
                  • 32

                  #9
                  The Combo box name is correct, when I changed the Me! To ME.
                  I received this Error message (Method or Data member not found)

                  Comment

                  • mshmyob
                    Recognized Expert Contributor
                    • Jan 2008
                    • 903

                    #10
                    Use the little reply button on the message - not the normal reply button. For some reason using the normal reply button doesn't work.

                    Comment

                    • colintis
                      Contributor
                      • Mar 2010
                      • 255

                      #11
                      Have you tried using this one?
                      Code:
                      docmd.openreport strReportName , acPreview , strCriteria
                      As I see it should be somewhere typed incorrect but not the code you posted.

                      Comment

                      • jimatqsi
                        Moderator Top Contributor
                        • Oct 2006
                        • 1290

                        #12
                        Did you copy and paste this error message, or retype it?
                        the error is ( 2465 : Microsoft office can't find the field ' ContractsStstus ' referred to in your expression

                        I ask, because I see the spelling of the object name is different in the error message from what you said it was.
                        One is ContractsStstus , with status spelled incorrectly, the other is spelled correctly. Maybe you've just got a typo.

                        Jim

                        Comment

                        • nebula53
                          New Member
                          • Aug 2010
                          • 32

                          #13
                          Jim there where Typo error when I copied the message.

                          Comment

                          • nebula53
                            New Member
                            • Aug 2010
                            • 32

                            #14
                            Please find the attached to understand the concept
                            Attached Files

                            Comment

                            • mshmyob
                              Recognized Expert Contributor
                              • Jan 2008
                              • 903

                              #15
                              Very sloppy programming practices. The message is simple: Access cannot find a field or control named "ContractStatus ". Simply because it does not exist. Your control name is [Contract Status] - with a space. You therefore need to wrap the control name or field name in square brackets.

                              Making a few minor changes to Jimatqsi code you should have:

                              Code:
                              Dim strCriteria As String
                              Dim strReportName As String
                              
                              strCriteria = "[Contract Status]='" & Me![Contract Status] & "'"
                              strReportName = "PMCONTRACTS"
                              
                              DoCmd.OpenReport strReportName, acPreview, , strCriteria
                              Note:
                              1. The wrapping of the control name in square brackets to take into account the bad habit of using spaces.
                              2. Changing [Status]= to [Contract Status]= since there is no Status control or field in your report.
                              3. I added an extra comma in the openreport line since strCriteria is a SQL expression not a filter name.


                              cheers,

                              Comment

                              Working...