Results 1 to 9 of 9
  1. #1
    grad2009 is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    27

    OpenReport function

    hello all,
    i wrote this function in a click event of a boutton
    Code:
    DoCmd.OpenReport "customer_account", acViewPreview, , "[nam]='" & Me.Combo4 & "'"
    can i add another condition beside the one in the function. In other words, the last partion of the OpenReport function (condition) could be more than one.



    Regards with thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sure; just separate them with "And". Make sure that in your quoting, only the form references are outside the quotes.

    DoCmd.OpenReport "customer_account", acViewPreview, , "[nam]='" & Me.Combo4 & "' AND OtherNumericField = " & Me.Textbox
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    grad2009 is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    27
    Thank you very much pbaldy, i am sorry for being late i was in a trip.

    i tried (And) in the condition but there are still errors

    the code i wrote is
    Code:
    DoCmd.OpenReport "customer_account", acViewPreview, , "[nam]='" & Me.Combo4 & "' AND Cdate(fdate) < Cdate(dat) AND Cdate(ldate) > Cdate(dat)"
    fdate, and ldate the names of two textboxes in a form, dat the date which is in customer_account report.

    when i click the boutton, it prompts to enter fdate, and ldate but i already entered them in the textboxes in the form.
    could you please find the reason of that problem ?
    thank you again

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The textbox values need to be concatenated into the string, just as you did with Combo4. Note that date/time values need to be surrounded by #, similar to how the text value is surrounded by single quotes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    grad2009 is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    27
    i wrote the folloing
    Code:
    DoCmd.OpenReport "customer_account", acViewPreview, , "[nam]='" & Me.Combo4 & "' AND #&Cdate(fdate)&# < #Cdate(dat)# AND #&Cdate(ldate)&# > #Cdate(dat)#"
    an error occur as in the attachment

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, I said "just as you did Combo4". Try this:

    "[nam]='" & Me.Combo4 & "' AND Cdate(dat) > #" & Cdate(Me.fdate) & "# AND Cdate(dat) < #" & Cdate(Me.ldate) & "#"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Datagopherdan is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Dec 2008
    Posts
    220
    Here's another route you can take. This allows the user to select no criteria, some criteria, or all criteria. It offers more flexibility Below is the basic syntax that you would use.

    Code:
    Dim strDesc As String
    Dim strCity As String
    Dim strSalesDate As String
    Dim strPropSize As String
    strSQL = ""
    If Len(Me.cmbLandBldgProp) > 0 Then
        If Len(strSQL) > 0 Then
            strSQL = strSQL & " AND " & "[Land_Bldg_Desc] in (""" & Me.cmbLandBldgProp & """) "
        Else
            strSQL = "[Land_Bldg_Desc] in (""" & Me.cmbLandBldgProp & """) "
        End If
    End If
    If Len(Me.cmbCityCat) > 0 Then
        If Len(strSQL) > 0 Then
            strSQL = strSQL & " AND " & "[City] in (""" & Me.cmbCityCat & """) "
        Else
            strSQL = "[City] in (""" & Me.cmbCityCat & """) "
        End If
    End If
    If Len(Me.txtDateFrom) > 0 Then
        If Len(strSQL) > 0 Then
            strSQL = strSQL & " AND " & "[Sales_Date] Between #" & Me.txtDateFrom & "# and #" & Me.txtDateTo & "# "
        Else
        strSQL = "[Sales_Date] Between #" & "[Sales_Date] Between #" & Me.txtDateFrom & "# and #" & Me.txtDateTo & "# "
        End If
    End If
    If Len(Me.txtAcFrom) > 0 Then
        If Len(strSQL) > 0 Then
            strSQL = strSQL & " AND " & "[Prop_Size_Ac] Between " & Me.txtAcFrom & " and " & Me.txtAcTo & " "
        Else
            strSQL = "[Prop_Size_Ac] Between " & Me.txtAcFrom & " and " & Me.txtAcTo & " "
        End If
    End If
    If Len(strSQL) > 0 Then
        strSQL = Left(strSQL, Len(strSQL) - 1)
        DoCmd.OpenReport "MyReport", acPreview, , strSQL
    Else
        DoCmd.OpenReport "MyReport", acPreview
    End If
    Quote Originally Posted by grad2009 View Post
    i wrote the folloing
    Code:
    DoCmd.OpenReport "customer_account", acViewPreview, , "[nam]='" & Me.Combo4 & "' AND #&Cdate(fdate)&# < #Cdate(dat)# AND #&Cdate(ldate)&# > #Cdate(dat)#"
    an error occur as in the attachment

  8. #8
    grad2009 is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    27
    Thank you very much pbaldy. now it is doing well. there is no error

    thank you very much for all.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 12-10-2018, 05:24 PM
  2. OpenReport Command with Double Check Where Statement
    By Robert M in forum Programming
    Replies: 3
    Last Post: 09-17-2009, 04:01 PM
  3. Can docmd.openreport print X copies on Y printer?
    By Coolpapabell in forum Reports
    Replies: 1
    Last Post: 09-02-2009, 08:35 AM
  4. Want function to get current function name
    By Davis DeBard in forum Programming
    Replies: 2
    Last Post: 08-13-2009, 05:02 AM
  5. Can I pass "sort by" using DoCmd.OpenReport
    By alsoto in forum Reports
    Replies: 3
    Last Post: 04-16-2009, 08:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums