Error 3075, 2448: Cannot Assign Value - Access 2003

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    Error 3075, 2448: Cannot Assign Value - Access 2003

    Hey gang!

    Below code allows me to search my database though all fields included on the form. Works great. Small issue, when I fetch partial phrases, if they contain an apostrophy, say, "Ferris Bueller's Day Off", Access does not understand it an gives me either ther 3075 error, or the other.

    What are your thoughts on that?

    Option Compare Database
    Option Explicit

    'Refresh form screen for new data entry
    Private Sub ResetMeScreen_C lick()
    DoCmd.Close 'the form must close, then reopened
    DoCmd.OpenForm "DataCentralRep ort"
    End Sub
    'Search button
    Private Sub SearchMeData_Cl ick()
    Const cInvalidDateErr or As String = "Please enter date in proper format to continue..."

    'Date format catcher. This keeps the data clean and standard
    Dim strWhere As String 'Dimensioned to be called through command
    Dim strError As String 'Dimensioned to be called below
    strWhere = "1=1"
    If Not IsNull(Me.AsTo) Then 'Loads data searched if available
    strWhere = strWhere & " AND " & "DataCentra l.[AsTo] = '" & Me.AssignedTo & "'"
    End If
    If Not IsNull(Me.OpToT hen 'Loads data searched if available
    strWhere = strWhere & " AND " & "DataCentra l.[OpTo= '" & Me.OpenedBy & "'"
    End If
    If Nz(Me.Status) <> "" Then 'Loads data searched if available
    strWhere = strWhere & " AND " & "DataCentra l.[Status] = '" & Me.Status & "'"
    End If
    If Nz(Me.Category) <> "" Then 'Loads data searched if available
    strWhere = strWhere & " AND " & "DataCentra l.[Category] = '" & Me.Category & "'"
    End If
    If Nz(Me.CoName) <> "" Then 'Loads data searched if available
    strWhere = strWhere & " AND " & "DataCentra l.[CoName] = '" & Me.CoName & "'"
    End If
    If Nz(Me.Code) <> "" Then 'Loads data searched if available
    strWhere = strWhere & " AND " & "DataCentra l.[Code] = '" & Me.Code & "'"
    End If
    If Nz(Me.Priority) <> "" Then 'Loads data searched if available
    strWhere = strWhere & " AND " & "DataCentra l.[Priority] = '" & Me.Priority & "'"
    End If
    If IsDate(Me.Begin ningDate) Then 'Loads data searched if dates available
    strWhere = strWhere & " AND " & "DataCentra l.[TodayDate] >= " & GetDateFilter(M e.BeginningDate )
    ElseIf Nz(Me.Beginning Date) <> "" Then
    strError = cInvalidDateErr or
    End If
    If IsDate(Me.Endin gDate) Then 'Loads data searched if dates available
    strWhere = strWhere & " AND " & "DataCentra l.[TodayDate] <= " & GetDateFilter(M e.EndingDate)
    ElseIf Nz(Me.EndingDat e) <> "" Then
    strError = cInvalidDateErr or
    End If
    If Nz(Me.ContactPe rson) <> "" Then 'Loads data searched if available
    strWhere = strWhere & " AND " & "DataCentral.Co ntactPerson Like '*" & Me.ContactPerso n & "*'"
    End If
    If Nz(Me.Items) <> "" Then 'Loads data searched if available
    'Like helps get part of the text then searched
    strWhere = strWhere & " AND " & "DataCentral.It ems Like '*" & Me.IssuesItems & "*'"
    End If
    'If Nz(Me.LegacyDat e) <> "" Then 'Loads data searched if dates available
    'strWhere = strWhere & " AND " & "DataCentral.Le gacyDate Like '*" & Me.LegacyDate & "*'"
    'End If
    If Nz(Me.ID) <> "" Then 'Loads data searched if dates available
    strWhere = strWhere & " AND " & "DataCentra l.ID Like '*" & Me.ID & "*'"
    End If


    If strError <> "" Then 'Pop up catch when search is cancelled
    MsgBox "You decided to cancel your search..." 'strError
    Else
    If Not Me.FormFooter.V isible Then 'results loads in additional form in footer
    Me.FormFooter.V isible = True
    DoCmd.MoveSize Height:=Me.Wind owHeight + Me.FormFooter.H eight
    End If
    Me.DataCentralR esultsForm.Form .Filter = strWhere
    Me.DataCentralR esultsForm.Form .FilterOn = True
    End If
    End Sub
    Function GetDateFilter(d tDate As Date) As String
    GetDateFilter = "#" & Format(dtDate, "MM/DD/YYYY") & "#"
    End Function
    Any information you have is appreciated.

    My apologies re; Code tags, too long of a procedure, couldn't add CODE=VB.

    Have a great week-end, thanks!

    Dököll
    Last edited by Dököll; Nov 30 '07, 08:05 PM. Reason: Removing code tags;-)
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Do a Replace on the string to change all single quotes to double single quotes.

    'He's'
    That confuses the SQL engine because it will see 'He' as a string but will not know what to do with s'. Double single quotes tell it to use the character and not to break the string and that the string continues on.

    Comment

    • Dököll
      Recognized Expert Top Contributor
      • Nov 2006
      • 2379

      #3
      Originally posted by Rabbit
      Do a Replace on the string to change all single quotes to double single quotes.

      'He's'
      That confuses the SQL engine because it will see 'He' as a string but will not know what to do with s'. Double single quotes tell it to use the character and not to break the string and that the string continues on.
      Pretty special, will give that a whirl!

      Thanks:-)

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Good luck.

        Comment

        • wvmitchell
          New Member
          • Oct 2007
          • 42

          #5
          Single quotes can create headaches, but you can put this in a standard module & then use it any time you're searching for strings. It doubles-up any single quotes as Rabbit said. It accepts a Variant, so NULLs won't break it, it just returns a zero-length string.

          Code:
          Function FixQuotes(text) As String
              If Len(Nz(text, "")) = 0 Then Exit Function
              FixQuotes = Replace(text, "'", "''")
          End Function

          Comment

          • Dököll
            Recognized Expert Top Contributor
            • Nov 2006
            • 2379

            #6
            Hey gang!

            It looks like removing single quotes in this case redenred the search unusable. I am certain I am missing the big picture:

            [CODE=VB]

            If Nz(Me.ID) <> "" Then 'Loads data searched if dates available
            strWhere = strWhere & " AND " & "DataCentra l.ID Like '*" & Me.ID & "*'"
            End If


            [/CODE]

            I really need to rid of the error for the above portion. I intend to remove the Like operator for the others.

            So removing the single quotes in above give me error number: 3075, as in the previous.

            It's probably pretty simple:-)

            In a bit, and thanks!

            Comment

            • Dököll
              Recognized Expert Top Contributor
              • Nov 2006
              • 2379

              #7
              I wondered if something like this would work to catch the error popping up:

              [CODE=VB]

              If Err.Number = 3075 Then
              .....
              Else
              .....
              End If

              [/CODE]

              Perhaps I can surpress the incoming error to tell VBA it's okay to process. Will let you know...

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                Originally posted by Dököll
                Hey gang!

                It looks like removing single quotes in this case redenred the search unusable. I am certain I am missing the big picture:

                [CODE=VB]

                If Nz(Me.ID) <> "" Then 'Loads data searched if dates available
                strWhere = strWhere & " AND " & "DataCentra l.ID Like '*" & Me.ID & "*'"
                End If


                [/CODE]

                I really need to rid of the error for the above portion. I intend to remove the Like operator for the others.

                So removing the single quotes in above give me error number: 3075, as in the previous.

                It's probably pretty simple:-)

                In a bit, and thanks!
                Removing single quotes? We never said to remove single quotes. You have to do the opposite. In a string with single quotes, you have to double up on the single quotes.

                Also, that snippet of code shouldn't throw an error in of itself.

                Comment

                • Dököll
                  Recognized Expert Top Contributor
                  • Nov 2006
                  • 2379

                  #9
                  Originally posted by Rabbit
                  Removing single quotes? We never said to remove single quotes. You have to do the opposite. In a string with single quotes, you have to double up on the single quotes.

                  Also, that snippet of code shouldn't throw an error in of itself.
                  What do you know, I missed the pretty picture "...change all single quotes to double single quotes..."

                  I see now.

                  I think I read "...change all single quotes..." and kept on.

                  Alright, I'll give it another go. Many thanks, gang!

                  Dököll

                  Comment

                  Working...