Results 1 to 10 of 10
  1. #1
    kelann is offline Learning ... thank you!!
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    132

    Correct Button Syntax


    Hi, all!

    Access is not liking my code, but it's not beign specific.

    Code:
    Private Sub Command120_Click()
    DoCmd.OpenReport "GetOrgInfoRep", acViewPreview, , , (OrganizationsT.OrgEnvironmental = -1 And Me.CircleYPEnvironmental = "l") Or (OrganizationsT.OrgHealthcare = -1 And Me.CircleYPHealthcare = "l") Or (OrganizationsT.OrgYouthMentorship = -1 And Me.CircleYPYouthMentorship = "l") 
    End Sub
    I'm comparing wanting to get the Report (GetOrgInfoRep), which is called from a button on a different report (EngageSelectedYPRep) but only for organizations where the OrgField (a checkbox) (from the OrganizationsT) is checked AND a similarly-named text field on this form has the value of "l" (which, in Wingdings, makes a circle).

    Thanks for any thoughts on correcting my language!

    --ak

  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
    I think you have it in the wrong position, and it has to be a string argument. Try:

    Code:
    DoCmd.OpenReport "GetOrgInfoRep", acViewPreview, , "(OrganizationsT.OrgEnvironmental = -1 And Me.CircleYPEnvironmental = 'l') Or (OrganizationsT.OrgHealthcare = -1 And Me.CircleYPHealthcare = 'l') Or (OrganizationsT.OrgYouthMentorship = -1 And Me.CircleYPYouthMentorship = 'l')"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    kelann is offline Learning ... thank you!!
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    132
    Thank you!

    I've put it in there, and it's definitely progress: No errors!

    However, it's not recognizing my "Me" fields -- I get the little popup asking for the values for each one.

    These "Me" fields are all set up following this pattern:
    Control Source: =IIf([YPArtsCulture]=-1,"l","")
    Other: CircleYPArtsCulture

    So I was using Me.CircleYPArtsCulture to represent it -- is that incorrect?

    These exist on the report with the button (that you have helped fix the code for above), but they do not exist on the report that the button opens. I want it to open the report only for the organizations that meet one of the comparison criteria. I tried moving the Me fields out of the header, but it didn't help.

    With thanks!

  4. #4
    kelann is offline Learning ... thank you!!
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    132
    I should add that if I put in values, it pulls correctly -- I just can't get it to pull the values from the current "Me" report.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, I missed that. In that position, I'd expect a field name, not a reference.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    The Me qualifier alias works only in VBA, not in queries nor in ControlSource property.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    kelann is offline Learning ... thank you!!
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    132
    Okay! Progress!

    I've done some reworking of the fields, and I've got it working like this:

    Code:
    DoCmd.OpenReport "GetOrgInfoRep", acViewPreview, , "OrgArtsCultureC = '" & Reports!EngageSelectedYPRep!YPArtsCultureC & "'"
    
    
    Can you please tell me how would I add an additional one to it with an "OR" connection?

    Something like

    Code:
    DoCmd.OpenReport "GetOrgInfoRep", acViewPreview, , "OrgArtsCultureC = '" & Reports!EngageSelectedYPRep!YPArtsCultureC & "'" Or "OrgBusinessC = '" & Reports!EngageSelectedYPRep!YPBusinessC & "'"
    
    

    When I do it like the above, I get a type mismatch -- I double-checked all the calculated fields, and the "Result Type" is Text for each.

    Thank you, thank you, thank you -- I cannot believe that I am seeing a light at the end of this looooooooooooooon tunnel!!

    --ak

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You've made a common mistake. Take out the quotes in red:


    DoCmd.OpenReport "GetOrgInfoRep", acViewPreview, , "OrgArtsCultureC = '" & Reports!EngageSelectedYPRep!YPArtsCultureC & "'" Or "OrgBusinessC = '" & Reports!EngageSelectedYPRep!YPBusinessC & "'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    kelann is offline Learning ... thank you!!
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    132
    Thank you so much, everyone!

    Based upon your help, with lots of reworking -- it's very different from how it started -- it's working completely!!!

    I can't tell you how much I appreciate all of your help.

  10. #10
    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. Correct Syntax
    By bidbud68 in forum Programming
    Replies: 6
    Last Post: 10-19-2012, 01:09 AM
  2. Correct Syntax For DoCmd
    By bidbud68 in forum Programming
    Replies: 3
    Last Post: 10-18-2012, 03:12 PM
  3. SQL Correct Syntax
    By tbassngal in forum Queries
    Replies: 11
    Last Post: 09-01-2011, 01:55 PM
  4. dcount syntax correct?
    By lbgtp in forum Reports
    Replies: 2
    Last Post: 12-29-2010, 10:01 AM
  5. What is the correct syntax for
    By giladweil in forum Access
    Replies: 1
    Last Post: 07-29-2010, 04:56 AM

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