problem with spaces

  • Thread starter Thread starter dirk van waes
  • Start date Start date
D

dirk van waes

hi,
On my continous form I have a textbox (znaam) in the form-heading. On the
"change"-event, I look in my recordset for a match with the text I type ,
and then I try to go to that record on my form.
This works fine as long as I do not type a space. When I do that(as in "De
Bock") access looks always for a text without the space at the end, and it
is impossible to type a character after the space.( since the space always
seems to disappear).
What should I do to avoid this error?
TIA
Dirk

Dim mijnset As Recordset
Me.RecordSource = "SELECT leden.NAAM FROM leden ORDER BY leden.NAAM;"
Set mijnset = Me.RecordsetClone
mijnset.FindFirst "NAAM like '" & Me!znaam & "*'"
If Not mijnset.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
Me!znaam.SetFocus
Me!znaam.SelStart = Len(Me!znaam)
 
dirk said:
On my continous form I have a textbox (znaam) in the form-heading. On the
"change"-event, I look in my recordset for a match with the text I type ,
and then I try to go to that record on my form.
This works fine as long as I do not type a space. When I do that(as in "De
Bock") access looks always for a text without the space at the end, and it
is impossible to type a character after the space.( since the space always
seems to disappear).

Dim mijnset As Recordset
Me.RecordSource = "SELECT leden.NAAM FROM leden ORDER BY leden.NAAM;"
Set mijnset = Me.RecordsetClone
mijnset.FindFirst "NAAM like '" & Me!znaam & "*'"
If Not mijnset.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
Me!znaam.SetFocus
Me!znaam.SelStart = Len(Me!znaam)


The Change event occurs before the typed data is assigned to
the text box's Value property. This means that you are
searching for something other than what you are typing. To
get what you are typing as you enter each character, use the
text box's Text property instead of the Value property.

It makes no sense for you to be setting the form's
RecordSource property in this change event. I think you
should get rid of that line.

Since you are typing in the znaam text box, there is no need
to set the focus to it. The cursor should be not affected
by your code, so there is no need to set SelStart either.

Sub znaam_Change()
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "NAAM like '" & Me!znaam.Text & "*'"
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End If
End With
End Sub
 
Hello Marsh,

Thanks for looking into my problem. I changed my code a little bit, and now
it works the way I want;
However, you wrote:

Since you are typing in the znaam text box, there is no need
to set the focus to it. The cursor should be not affected
by your code, so there is no need to set SelStart either.

that isn't true. The cursor is clearly affected. Strangely enough, each time
I type a character, that character is highlighted, and when I try to type a
second character, I overwrite the first character! so I added again this 2
lines:

Me!znaam.SetFocus
Me!znaam.SelStart = Len(Me!znaam) + 1

and now everything works fine. I have no explanation for this, but the
important thing is that it works!

Greetings from Belgium
Dirk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top