Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Key press cancelling (Access 97/SR2)

    I have a unbound text box which is used for entering search criteria.
    The search crashes if an apostrophe is entered ( ' ).
    I was currently have an if statement in the on key down event to deal with pressing enter (runs the search):

    If KeyCode = 13 Then
    Me.Command10.SetFocus
    Command10_Click

    And I was planning on putting another if statement in to deal with the apostrophe, however, it doesn't seem to do anything in the on key down event, so I put it in the on key press event, which work with my test (which was to display a msgbox) - but I now can't seem to get it to return nothing i.e. when the user presses apostrophe, nothing happens.

    I tried the following but it returned the error - "Invalid use of null":

    If KeyAscii = 39 Then KeyAscii = Null

    Any help would be much appreciated.

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Key press cancelling (Access 97/SR2)

    What is the code you use to do the search ?
    Francois

  3. #3
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Key press cancelling (Access 97/SR2)

    It selects all the bits from the criteria entered, and puts them in a SQL statement where it is the set to a recordsource of a form. So the form then displays all the matches. The actual code is something like:

    stringsql = stringsql & " and (EstablishmentName Like '" & en & "' )"
    FromSQL = " From dbo_tbleducation where 'a'='a' " & stringsql
    stringsql = "SELECT dbo_tbleducation.* " & FromSQL

    Theres loads of other bits depending on what other search criteria is selected, but thats the basics of it.

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Key press cancelling (Access 97/SR2)

    Change the first line to :

    <pre>stringsql = stringsql & " and (EstablishmentName Like " & chr(34) & en & chr(34) & ")"</pre>

    Francois

  5. #5
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Key press cancelling (Access 97/SR2)

    Thanks Francois - worked perfectly.

Posting Permissions

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