Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    May 2003
    Location
    Pennsylvania, USA
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Quotes in Strings (Access 2003)

    Even after reading Hans' posts on quotes within strings, I still can't get my code to work! I want to take a value from a combo box on a form and use it to construct a filter for use in generating a report. There could be embedded spaces in the filter condition, so I need the filter condition to be in quotes (i.e. [Owner] = "Filter Condition", where Owner is the name of the field in the underlying table).


    Here is my code:

    Private Sub Report_Open(Cancel As Integer)

    Dim FilterVal As String
    Dim x As String

    FilterVal = Forms!Beginning!FilterValue
    Me.Filter = "[Owner] = " & Chr(34) FilterVal & chr(34)
    x = Me.Filter
    Debug.Print x

    If FilterVal = " All" Then
    Me.FilterOn = False
    Else
    Me.FilterOn = True
    End If

    DoCmd.OpenReport "MyReport", acViewPreview


    Whether I use Chr(34) or Chr(39), I get either a syntax error or too many quotes in Me.Filter.

    All help would be much appreciated!

    Don.

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

    Re: Quotes in Strings (Access 2003)

    The line

    Me.Filter = "[Owner] = " & Chr(34) FilterVal & chr(34)

    is missing an ampersand, it should be

    Me.Filter = "[Owner] = " & Chr(34) & FilterVal & Chr(34)

  3. #3
    Star Lounger
    Join Date
    May 2003
    Location
    Pennsylvania, USA
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Quotes in Strings (Access 2003)

    Isn't it strange how you can stare at something for a long time and completely miss the obvious??

    Thanks much, Hans--that did the trick.

    Regards,

    Don.

Posting Permissions

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