Results 1 to 12 of 12
  1. #1
    Tchelo is offline Novice
    Windows 10 Access 2021
    Join Date
    Aug 2023
    Posts
    5

    text box donīt accept caracter space

    in this code donīt accept caracter space on textbox Pesquisar:

    Private Sub Pesquisar_Change()
    Me.Pesquisar.AllowAutoCorrect = False
    Dim filtro As String
    filtro = "[ENDERECO] like '*" & Me.Pesquisar.Text & "*' Or [CNPJ] like '*" & Me.Pesquisar.Text & "*' or [IE] like '*" & Me.Pesquisar.Text & "*' or [IM] like '*" & Me.Pesquisar.Text & "*' or [TELEFONE] like '*" & Me.Pesquisar.Text & "*' or [CONTACORRENTE] like '*" & Me.Pesquisar.Text & "*' or [BANCOEAGENCIA] like '*" & Me.Pesquisar.Text & "*' or [RAZAOSOCIAL] like '*" & Me.Pesquisar.Text & "*' or REPRESENTANTE like '*" & Me.Pesquisar.Text & "*' or [CPF] like '*" & Me.Pesquisar.Text & "*' or [EMAIL] like '*" & Me.Pesquisar.Text & "*' or [VALIDADE] like '*" & Me.Pesquisar.Text & "*'"
    Me.Form.filter = filtro
    Me.Form.FilterOn = True
    Me.Pesquisar.SelStart = Len(Me.Pesquisar.Text)


    'Me.Pesquisar.SelStart = 255 'permite digitar mais de uma letra no textbox
    End Sub

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    You need to add code to deal with the space key.

    see this link... https://access-programs.com/ms-acces...h-as-you-type/



    Code:
    Private Sub txtSearch_Change()
    If blnSpace = False Then
     Me.Requery
     Refresh
     txtSearch.SetFocus
     txtSearch.SelStart = Len(Me.txtSearch.Text)
    End If
    End Sub
    
    
    
    Private Sub txtSearch_KeyPress(KeyAscii As Integer)
    If KeyAscii = 32 Then
      blnSpace = True
    Else
      blnSpace = False
    End If
    End Sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    Tchelo is offline Novice
    Windows 10 Access 2021
    Join Date
    Aug 2023
    Posts
    5
    Donīt work, itīs same way
    Actual codes:

    Private Sub Pesquisar_Change()
    If blnSpace = False Then
    Me.Requery
    Refresh
    Pesquisar.SetFocus
    Pesquisar.SelStart = Len(Me.Pesquisar.Text)
    End If


    Me.Pesquisar.AllowAutoCorrect = False
    Dim filtro As String
    filtro = "[ENDERECO] like '*" & Me.Pesquisar.Text & "*' Or [CNPJ] like '*" & Me.Pesquisar.Text & "*' or [IE] like '*" & Me.Pesquisar.Text & "*' or [IM] like '*" & Me.Pesquisar.Text & "*' or [TELEFONE] like '*" & Me.Pesquisar.Text & "*' or [CONTACORRENTE] like '*" & Me.Pesquisar.Text & "*' or [BANCOEAGENCIA] like '*" & Me.Pesquisar.Text & "*' or [RAZAOSOCIAL] like '*" & Me.Pesquisar.Text & "*' or REPRESENTANTE like '*" & Me.Pesquisar.Text & "*' or [CPF] like '*" & Me.Pesquisar.Text & "*' or [EMAIL] like '*" & Me.Pesquisar.Text & "*' or [VALIDADE] like '*" & Me.Pesquisar.Text & "*'"
    Me.Form.filter = filtro
    Me.Form.FilterOn = True
    Me.Pesquisar.SelStart = Len(Me.Pesquisar.Text)
    'Me.Pesquisar.SelStart = 255 'permite digitar mais de uma letra no textbox
    End Sub


    Private Sub Pesquisar_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyAscii = 32 Then
    blnSpace = True
    Else
    blnSpace = False
    End If
    End Sub

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    That code shouldn't even run
    (KeyCode As Integer, Shift As Integer)

    If KeyAscii = 32 Then

    If you put break points at the start of change and keydown events and step through the code you might find that the change event doesn't run.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Think the issue is that by setting the filter the text box temporarily loses the focus - and in doing so strips off any trailing spaces.

    Use debug.print len(Pesquisar.text) before and after the filteron line to test

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Code:
    Private Sub Pesquisar_KeyDown(KeyCode As Integer, Shift As Integer)
    Code:
    Private Sub txtSearch_KeyPress(KeyAscii As Integer)
    Different events.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    Tchelo is offline Novice
    Windows 10 Access 2021
    Join Date
    Aug 2023
    Posts
    5
    now event is correct (ok)


    see the code when i type space, itīs exactly like CJ_London say "Think the issue is that by setting the filter the text box temporarily loses the focus - and in doing so strips off any trailing spaces."
    but how to solve this ?:

    Private Sub Pesquisar_Change()
    MsgBox (Len(Pesquisar.Text)) 'HERE MSGBOX SHOW LEN IS 1
    If blnSpace = False Then
    'Me.Requery
    'Refresh
    Pesquisar.SetFocus
    MsgBox (Len(Pesquisar.Text)) 'HERE MSGBOX SHOW LEN IS 1
    Pesquisar.SelStart = Len(Me.Pesquisar.Text)
    MsgBox (Len(Pesquisar.Text)) 'HERE MSGBOX SHOW LEN IS 1
    End If


    Me.Pesquisar.AllowAutoCorrect = False
    Dim filtro As String
    filtro = "[ENDERECO] like '*" & Me.Pesquisar.Text & "*' Or [CNPJ] like '*" & Me.Pesquisar.Text & "*' or [IE] like '*" & Me.Pesquisar.Text & "*' or [IM] like '*" & Me.Pesquisar.Text & "*' or [TELEFONE] like '*" & Me.Pesquisar.Text & "*' or [CONTACORRENTE] like '*" & Me.Pesquisar.Text & "*' or [BANCOEAGENCIA] like '*" & Me.Pesquisar.Text & "*' or [RAZAOSOCIAL] like '*" & Me.Pesquisar.Text & "*' or REPRESENTANTE like '*" & Me.Pesquisar.Text & "*' or [CPF] like '*" & Me.Pesquisar.Text & "*' or [EMAIL] like '*" & Me.Pesquisar.Text & "*' or [VALIDADE] like '*" & Me.Pesquisar.Text & "*'"
    Me.Form.filter = filtro
    MsgBox (Pesquisar.Text) ' HERE MSGBOX BRING NOTHING
    MsgBox (Len(Pesquisar.Text)) 'HERE MSGBOX SHOW LEN IS 0
    Me.Form.FilterOn = True
    MsgBox (Len(Pesquisar.Text)) 'HERE MSGBOX SHOW LEN IS 0
    Me.Pesquisar.SelStart = Len(Me.Pesquisar.Text)
    End Sub

  8. #8
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Works for me. See attached example.

    try putting a debug.print after your filter string so you can see what it resolves to.
    Attached Files Attached Files
    Last edited by moke123; 08-01-2023 at 05:10 PM.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  9. #9
    Tchelo is offline Novice
    Windows 10 Access 2021
    Join Date
    Aug 2023
    Posts
    5
    Donīt work. See my project.
    Attached Files Attached Files

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    would help if you disabled all the startup stuff, and clarified how we get to the problem - what do we type? where? do we click a button

  11. #11
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    First thing to do is add your declarations. You have none.
    Code:
    Option Compare Database
    Option Explicit
    "Private blnSpace As Boolean" needs to be in the forms module not a standard module as it is declared private.

    I added a debug.print which produced this filter string
    Code:
    [ENDERECO] Like "*a*" or [CNPJ] like "*a*"
    [ENDERECO] Like "*ab*" or [CNPJ] like "*ab*"
    [ENDERECO] Like "*abc*" or [CNPJ] like "*abc*"
    [ENDERECO] Like "*abcd*" or [CNPJ] like "*abcd*"
    [ENDERECO] Like "*abcde*" or [CNPJ] like "*abcde*"
    [ENDERECO] Like "*abcdef*" or [CNPJ] like "*abcdef*"
    [ENDERECO] Like "*abcdefg*" or [CNPJ] like "*abcdefg*"
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  12. #12
    Tchelo is offline Novice
    Windows 10 Access 2021
    Join Date
    Aug 2023
    Posts
    5
    The problem was the declarations, now it workīs !!!!
    Thanks a lot !!!!!
    SOLVED !!!!!!!!!!

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

Similar Threads

  1. query fields won't accept text
    By snowboarder234 in forum Queries
    Replies: 9
    Last Post: 05-27-2016, 02:39 PM
  2. Replies: 2
    Last Post: 02-07-2015, 11:20 PM
  3. Replies: 2
    Last Post: 10-17-2012, 01:35 PM
  4. Space between two text boxes
    By ashbear in forum Reports
    Replies: 3
    Last Post: 08-17-2011, 05:02 PM
  5. Setting a field to only accept text characters, not numbers
    By USAFA2012 in forum Database Design
    Replies: 2
    Last Post: 03-09-2010, 12:37 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