Results 1 to 9 of 9
  1. #1
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328

    Open form with OR And using expressions to filter

    Using A2007. This question hopefully a little simpler than the other recent post with similar title.



    I am opening a form and filtering it as follows:
    DoCmd.OpenForm "F_ErrorsMisc_Popup", , , "(ScoringBasis=""tot"" and (isnull(A) or isnull(B))) OR (ScoringBasis=""tod"" and (isnull(Distance) or Distance=0))"

    It works, but I hate having long expressions like this-(I’m a little dyslexic and I will be adding conditions) I would like to simplify by making Dim statements for the expressions on each side of OR so that I can have smaller expressions to modify if needed. Then, open the form with:

    Docmd.openform,”F_ErrorsMisc_Popup”, , , sWhere1 OR sWhere2

    I try it and just can’t seem to find the right sequence of quotation marks or whatever else is needed.. Always get errors like type mismatch etc.
    Any help much appreciated

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Have to concatenate variables with literal text.

    sWhere1 & " OR " & sWhere2
    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.

  3. #3
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    I don't understand "literal text", but it works great -just wish I had posted sooner.. I just can't seem to grasp the logic of some of these things. I will save it in my large list of How-To's. I guess I do the same when I add Swhere3.

    Thanks so much for the quick and accurate reply, much much appreciated.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The OR is not a variable - it is just a string of characters - it is not a variable that holds a value - you want it to be included in the compiled statement exactly as it is typed - literal text. Literal text must be delimited within quote (or apostrophe in some cases) marks.
    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.

  5. #5
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    Thanks again. When saving this in my "how to" files, I tried same expression in an already opened Form: me.filter= swhere1 "or" swhere2. Doesn't work there. I did find an Allen Browne post that included "and/or" in the dim statement that does work. Curious as to why different.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Don't know what you mean be included "and/or". Want to post code or provide link?

    me.filter= swhere1 "or" swhere2

    doesn't work because missing & concatenation characters.
    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
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    I probably didn't make it clear, but this is what I meant by including "or/and". I know don't need it, but saving this as an example in case I get a some long expressions later.

    Form.FilterOn = True
    Dim Filt3 As String
    Filt3 = "Boatname=""Bewitched"" or "
    Filt3 = Filt3 & "boatname=""Silkye"""
    Me.Filter = Filt3

    I can't find the Allen Browne link but did download the example long time ago and will send if you like. He had quite a few statements, strings, dates etc., followed with AND, any one of which may not have been used. So, had code to chop of the AND when final applying final filter.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I think I know the link (http://www.allenbrowne.com/ser-62code.html) but not seeing the Dim statement you describe. The VBA approach does not mix OR operator with AND. If you want to expand on the code and use OR operator it will get complicated.
    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.

  9. #9
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    I didn't mean to imply that I was trying to use both and & or in same Dim statement.. I just didn't know the proper word in VBA for a conjunction so put "and/or" down. It is interesting that the filter statement for opening is a different format for filtering while form is open.

    The link you show is the one that I used. I appreciate how much attention you giving this this.

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

Similar Threads

  1. Filter form on open
    By Xarkath in forum Forms
    Replies: 8
    Last Post: 07-17-2013, 10:51 AM
  2. Open Form and filter subform
    By gg80 in forum Programming
    Replies: 3
    Last Post: 09-04-2011, 05:05 PM
  3. Replies: 1
    Last Post: 08-01-2011, 04:17 PM
  4. filter when i open form
    By Balen in forum Forms
    Replies: 0
    Last Post: 08-12-2010, 02:31 PM
  5. How to open a form with filter applied?
    By rkm360 in forum Access
    Replies: 1
    Last Post: 03-18-2009, 09:27 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