RE: Search in field without overwrite
From: Geoffs (Geoffs_at_discussions.microsoft.com)
Date: 03/09/05
- Next message: Geoffs: "RE: Closing a form only if value is selected."
- Previous message: Allen Browne: "Re: Error for using Dlookup function in Subform"
- In reply to: Sky Warren: "Search in field without overwrite"
- Next in thread: Sky Warren: "RE: Search in field without overwrite"
- Reply: Sky Warren: "RE: Search in field without overwrite"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Geoffs: "RE: Closing a form only if value is selected."
- Previous message: Allen Browne: "Re: Error for using Dlookup function in Subform"
- In reply to: Sky Warren: "Search in field without overwrite"
- Next in thread: Sky Warren: "RE: Search in field without overwrite"
- Reply: Sky Warren: "RE: Search in field without overwrite"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|