RE: Search in field without overwrite

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Geoffs (Geoffs_at_discussions.microsoft.com)
Date: 03/09/05


Date: Wed, 9 Mar 2005 02:15:03 -0800

Hi,
There are lots of ways to achieve this, but simplest way to do this without
having to change the method you are currently using would be to place a new
TextBox control over the top of the "LastName" Textbox that is not bound to
the data. Call it "txtLastName". Since it is placed on the form after the
first TextBox was it will be on top by default, thereby hiding the "real"
"LastName" field. You have to hide it in this manner 'cos later on we will
want to give it Focus and you could not do that if we just set the Visible
property to False.
Change your KeyPress Sub to react to txtLastName_KeyPress, so that when your
user types into it you can assign the characters to your string variables.
Then add a line of code just before you call the "DoCmd.FindRecord" so that
you are searching on the real "LastName" ---- txtLastName.SetFocus
Then after the record is found we need to assign the "LastName" value to the
"txtLastName" TextBox to display it, and since we will need to do this every
time the user moves to a new record (since the REAL LastName Field is hidden)
then place this line of code in the Form_Current() Event
 LastName.Value = txtLastName.Value

TIP - whilst you are testing this and so that you know which control you are
looking at why not set the ForeColor to Red for txtLastName.

:-)

"Sky Warren" wrote:

> Hi to all,
>
> I have code that jumps to records that meet criterior of what's typed into a
> text box. The way it's supposed to work is a user types a few characters in
> the text box and any record(s) meeting the criterior become the current
> record.
>
> In my form I have several record fields including Last Name. I have a
> separate text box "LookupLast" bound to the Last Name field. The problem is
> when user types into LookupLast text box the Last Name field gets overwritten.
>
> Can anyone look at code below and see what can be done to make it work!!
>
> Below is VB code for LookupLast text box:
>
> Option Compare Database
> Option Explicit
> Dim strFind As String
> Dim datLastKeyPress As Date
>
> Private Sub LookupLast_KeyPress(KeyAscii As Integer)
> Dim strChr As String
> strChr = Chr(KeyAscii)
> If DateDiff("S", datLastKeyPress, Now) > 2 Then
> strFind = strChr
> Else
> strFind = strFind & strChr
> End If
> DoCmd.FindRecord strFind, acStart, , , , , True
> If Left(LookupLast, Len(strFind)) <> strFind Then
> strFind = strChr
> DoCmd.FindRecord strFind, acStart, , , , , True
> End If
> datLastKeyPress = Now
> End Sub



Relevant Pages

  • RE: Filter records based on user input
    ... property to get what is currently in the textbox. ... Private Sub txtFilter_Change ... which would filter your form based on the text in the textbox. ... It should filter the records as the user types the number. ...
    (microsoft.public.access.formscoding)
  • RE: Filter records based on user input
    ... I thought that the bookmark line would set the focus to the control in the ... property to get what is currently in the textbox. ... which would filter your form based on the text in the textbox. ... It should filter the records as the user types the number. ...
    (microsoft.public.access.formscoding)
  • RE: Filter records based on user input
    ... Private Sub txtFilter_Change ... which would filter your form based on the text in the textbox. ... It should filter the records as the user types the number. ...
    (microsoft.public.access.formscoding)
  • Re: help with search - using query
    ... or do you mean refer to the fields in the table? ... What I meant is let the user put the asterisks in the textbox, ... In the textbox: find where red is the only colour RED ... find where red is the first colour user types RED* ...
    (comp.databases.ms-access)