Results 1 to 10 of 10
  1. #1
    pimlicosnail is offline Novice
    Windows XP Access 2002
    Join Date
    Feb 2010
    Posts
    6

    Syntax Contains Problem

    Hello, I'm having a problem with developing code to generate a report with only those records containing the value in an unbound textbox. I'm using the OnClick event on the Preview Report button on the form (I'd rather use this than create a query because I use the same report for other filters).



    Here is the code I'm using:

    Code:
    If Not IsNull(Me.Text21.Value) Then
    
        stDocName = "rptReport"
        DoCmd.OpenReport stDocName, acPreview, , Chr(34) & Me.Text21 & Chr(34) & "In ([fldTitle])"
    
    End If
    What is wrong with my code?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Try:
    DoCmd.OpenReport stDocName, acPreview, , "[fldTitle] = '" & Me.Text21 & "'")

  3. #3
    pimlicosnail is offline Novice
    Windows XP Access 2002
    Join Date
    Feb 2010
    Posts
    6
    Thanks for the info, but I'm actually looking for Contains vs Equals. How would I do that?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    I'm not sure you can do that with a filter. You'll just have to experiment. How many different values might you be looking for?

  5. #5
    pimlicosnail is offline Novice
    Windows XP Access 2002
    Join Date
    Feb 2010
    Posts
    6
    It's just one value in the unbound textbox.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    How about something like:
    Code:
    If Not IsNull(Me.Text21.value) Then
        stDocName = "rptReport"
        stWhereClause = "InStr(1,[fldTitle],'" & Me.Text21 & "') > 0"
        DoCmd.OpenReport stDocName, acPreview, , stWhereClause
    End If

  7. #7
    pimlicosnail is offline Novice
    Windows XP Access 2002
    Join Date
    Feb 2010
    Posts
    6
    That did the job! Thanks... however, is there a way to have it search all record fields (vs just fldTitle)?

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    It is *only* a filter you know. How about passing the value of Me.Text21 to the Report in the OpenArgs and then you can do whatever you need in the OnLoad event.

  9. #9
    pimlicosnail is offline Novice
    Windows XP Access 2002
    Join Date
    Feb 2010
    Posts
    6
    I'm not sure what you mean by passign the value to the report in the OpenArgs and do whatever in the OnLoad event.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Here's a couple of links that might offer some insite into what you are trying to achieve.
    http://allenbrowne.com/ser-62.html
    http://allenbrowne.com/AppFindAsUType.html

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

Similar Threads

  1. Syntax Error
    By KLynch0803 in forum Programming
    Replies: 11
    Last Post: 02-04-2010, 01:45 AM
  2. if or syntax help needed
    By techexpressinc in forum Queries
    Replies: 16
    Last Post: 01-11-2010, 08:03 AM
  3. Sql Syntax Query
    By Matthieu in forum Queries
    Replies: 4
    Last Post: 12-30-2009, 09:41 AM
  4. Looping syntax
    By fadiaccess in forum Access
    Replies: 1
    Last Post: 10-23-2009, 02:57 AM
  5. sql syntax error
    By SMAlvarez in forum Access
    Replies: 1
    Last Post: 03-12-2009, 09:43 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