Results 1 to 2 of 2
  1. #1
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72

    Keypress for Auto complete not quite working

    I have written some code that responds to a keypress event of a text box and auto completes the text, unfortunately it does not quite work. Here are the two functions I wrote:

    Function GetFldLike(Wtbl As String, Wfld As String, Wval As String) As String
    Dim db As Database
    Dim Lrs As DAO.Recordset
    Dim LSQL As String
    Dim LStr As String
    Set db = CurrentDb()
    LSQL = "SELECT " & Wfld & " FROM " & Wtbl & " WHERE " & Wfld & " LIKE '" & Wval & "';"
    Set Lrs = db.OpenRecordset(LSQL)
    If Lrs.EOF = False Then
    LStr = Lrs(Wfld)
    Else
    LStr = ""
    End If
    Lrs.Close


    Set Lrs = Nothing
    GetFldLike = LStr
    End Function

    Private Sub Company_KeyPress(KeyAscii As Integer)
    Dim Stmp As String
    If KeyAscii = Asc("\") Then
    If Me.Dirty Then
    Me.Dirty = False
    End If
    Stmp = GetFldLike("Addresses", "Company", Me.Company & "*")
    If Not (Stmp = "") Then
    Me.Company = Stmp
    End If
    End If
    End Sub

    The problem occurs when the Comapny text box is filled from the Stmp variable, afterwards Access sets the text box contents to "\". Oddly it works fine if I put a break point on the "Stmp = ..." line, something to do with the text box losing focus. I need a way of aborting / surpressing the key press event immediately after the "Me.Company = Stmp" line, that way Access won't change the text box again.
    Last edited by degras; 03-24-2011 at 09:22 AM.

  2. #2
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72
    I discovered that setting KeyAscii to 0 immediately after the "Me.Company = Stmp" line solves the problem.

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

Similar Threads

  1. Auto Complete Data
    By manicamaniac in forum Access
    Replies: 5
    Last Post: 09-14-2010, 03:38 PM
  2. New to access, looking for steps to complete
    By iamyourdemize in forum Access
    Replies: 1
    Last Post: 05-21-2010, 02:19 PM
  3. Making Access complete the To: in outlook
    By tlampher in forum Access
    Replies: 1
    Last Post: 02-16-2010, 06:14 PM
  4. Some advise for a complete novice...!
    By 450nick in forum Access
    Replies: 1
    Last Post: 09-11-2009, 02:23 AM
  5. Complete, noob help with where to start?
    By tragik in forum Queries
    Replies: 2
    Last Post: 06-29-2009, 09:20 AM

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