Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Dec 2008
    Location
    Gloucester, Gloucestershire, United Kingdom
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    where condition in VB (Access 2000 +)

    Hey everyone.

    OK, please excuse my ignorance...I want to open a report that shows the records that have a checkbox ticked...I could run this through a macro or query, but I'd like to know how to use the 'where' condition in the visual basic...if i knew this it could save so much time on other functions too!

    I already have a select combobox on my form to select the clients' topic e.g. restaurant, this works fine...but if I want to add anything to the where condition it just doesn't like what i put...I think i'm getting confused with sql and just don;t know how to say 'AND logoDisplayed' = yes in Visual basic! I have this so far...

    docmd.openreport "myreport", , acviewpreview, "Topic LIKE '" & Combo38 & "'"

    any ideas?

    Many thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: where condition in VB (Access 2000 +)

    The syntax for OpenReport is
    <code>
    DoCmd.OpenReport ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs
    </code>
    So acViewPreview should come immediately after the report name:
    <code>
    DoCmd.OpenReport "MyReport", acViewPreview, , "Topic Like '" & Me.Combo38 & "'"
    </code>
    If you want to add a condition:
    <code>
    DoCmd.OpenReport "MyReport", acViewPreview, , "Topic Like '" & Me.Combo38 & "' AND LogoDisplayed = True"
    </code>
    Notes:
    - If Combo38 doesn't contain wildcards such as ? or * you might as well use = instead of Like.
    - It's a good idea to give controls meaningful names, for example cboTopic instead of Combo38. This makes it much easier to understand the purpose of the control later on.

  3. #3
    New Lounger
    Join Date
    Dec 2008
    Location
    Gloucester, Gloucestershire, United Kingdom
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: where condition in VB (Access 2000 +)

    Hi Hans

    Thanks for this...I tried this before and I get an error message..?...well, not quite an error message, but an 'Enter Parameter Value' dialogue box comes up for the LogoDisplayed...?

    Thanks for the hints - the now cmboTopic does indeed have wildcard '*' as I've created an 'All' option in the topic list to show all records...hopefully this isn't causing a problem?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: where condition in VB (Access 2000 +)

    If you use a wildcard in the combo box, the use of Like is OK, and it's not the cause of the problem.

    If you're getting a parameter prompt for LogoDisplayed, it means that LogoDisplayed is not recognized as a valid field name in the report's record source. So either the name is misspelled, or there is no such field in the report's record source.

  5. #5
    New Lounger
    Join Date
    Dec 2008
    Location
    Gloucester, Gloucestershire, United Kingdom
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: where condition in VB (Access 2000 +)

    oh my goodness would you look at that...what a complete noobie.

    well Hans, I had checked the name etc, but not the control source - the problem was that I had a 'space' in the field name...all sorted, working great.

    Thanks a lot

Posting Permissions

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