Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2010
    Posts
    134
    Provided Answers: 1

    Unanswered: Do.cmd.OperQuery v OpenReport

    Hi there

    Can anyone spot why

    Private Sub ButtonOpen_Click()
    DoCmd.OpenReport "rpt_Apps_By_Owner", acViewReport, , GetCriteria()
    End Sub

    ... works but

    Private Sub ButtonOpen_Click()
    DoCmd.OpenQuery "qry_Apps_By_Owner", acViewQuery, , GetCriteria()
    End Sub

    ....doesnt'? Beats me so would be grateful..

  2. #2
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    DoCmd.OpenQuery only takes three parameters:
    The Query Name, The View Type, and the Data Mode.

    You are trying to use four parameters like you would in a report. Remove , , GetCriteria() and it should work fine.

    Steve

  3. #3
    Join Date
    Dec 2010
    Posts
    134
    Provided Answers: 1
    Hey.. thanks for that. That is a shame, as I need to pass the query criteria in order to get the specific record set. I guess therefore I am stuck with having to pull back the data in Report format.

  4. #4
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    I don't know what your GetCriteria method looks like, but can you add the necessary conditions to the actual query and have the query pull the required info from the form?

    You can also build a form to look like a query and set the data anyway you like in vba, all depends on what you are trying to accomplish

    Steve

  5. #5
    Join Date
    Dec 2010
    Posts
    134
    Provided Answers: 1
    Well I want to use a form to select certain criteria and run the query against that.

    Option Compare Database


    Private Function GetCriteria() As String
    Dim stDocCriteria As String
    Dim VarItm As Variant

    For Each VarItm In ListFilter.ItemsSelected
    stDocCriteria = stDocCriteria & "[Application] = '" & ListFilter.Column(0, VarItm) & "' OR "
    Next
    If stDocCriteria <> "" Then
    stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 4)
    Else
    stDocCriteria = "True"
    End If

    GetCriteria = stDocCriteria
    End Function


    Private Sub ButtonOpen_Click()
    DoCmd.OpenReport "rpt_app_data", acViewReport, , GetCriteria()
    End Sub

    .....is my current setup and as you see at the bottom, I have to run the report NOT the just the underlying query.

    Any pointers?

  6. #6
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    could you create a function that just returned the selected list items as a text string like: item1 or item2 or item3

    And then, in your query just call that function as the criteria for the Application field?

    You could then just call DoCmd.OpenQuery with 2 parameters

    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •