PC Review


Reply
Thread Tools Rate Thread

'Change Event' trouble

 
 
=?Utf-8?B?Q2l0eUd1eQ==?=
Guest
Posts: n/a
 
      17th Mar 2006
Hi,
I am fairly new to Access Vbasic programming.

What I am trying to do is have the 'Change Event' fire when
I enter any text into a text box. The 'Change Event' calls the
code but a problems arises when I start to look at the text entered.

The problem seems to be that the text read in is alway 1 key stroke
behind what is in the text box. For example:
1 - I enter "e" into the text box. The text box contains "e", but the code
detects
a null string when reading the text box contents
2 - I then enter "f", now the text box contains "ef", but the code detects
only "e"
when reading the text box contents
3 - I then enter "f", now the text box contains "eff", but the code detects
only "ef"
when reading the text box contents

What am I missing? Can any one shed some light on this?
Any help is greatly appreciated.



 
Reply With Quote
 
 
 
 
Brendan Reynolds
Guest
Posts: n/a
 
      17th Mar 2006

Are you looking at the Text property or the Value property of the text box
control? If you're referring to the control by name without specifying a
specific property, you're looking at the Value property. Unlike VB controls,
the Value property is the default property of an Access form control.

The following code displays the text as I enter it ...

Private Sub Text0_Change()

Me.Label2.Caption = Me.Text0.Text

End Sub

--
Brendan Reynolds
Access MVP

"CityGuy" <(E-Mail Removed)> wrote in message
news:7F98D6F2-337A-4B7B-8698-(E-Mail Removed)...
> Hi,
> I am fairly new to Access Vbasic programming.
>
> What I am trying to do is have the 'Change Event' fire when
> I enter any text into a text box. The 'Change Event' calls the
> code but a problems arises when I start to look at the text entered.
>
> The problem seems to be that the text read in is alway 1 key stroke
> behind what is in the text box. For example:
> 1 - I enter "e" into the text box. The text box contains "e", but the code
> detects
> a null string when reading the text box contents
> 2 - I then enter "f", now the text box contains "ef", but the code detects
> only "e"
> when reading the text box contents
> 3 - I then enter "f", now the text box contains "eff", but the code
> detects
> only "ef"
> when reading the text box contents
>
> What am I missing? Can any one shed some light on this?
> Any help is greatly appreciated.
>
>
>



 
Reply With Quote
 
=?Utf-8?B?Q2l0eUd1eQ==?=
Guest
Posts: n/a
 
      17th Mar 2006
I didn't know there was more than the text property.

Thanks for the tip, I will try applying what you said.

"Brendan Reynolds" wrote:

>
> Are you looking at the Text property or the Value property of the text box
> control? If you're referring to the control by name without specifying a
> specific property, you're looking at the Value property. Unlike VB controls,
> the Value property is the default property of an Access form control.
>
> The following code displays the text as I enter it ...
>
> Private Sub Text0_Change()
>
> Me.Label2.Caption = Me.Text0.Text
>
> End Sub
>
> --
> Brendan Reynolds
> Access MVP
>
> "CityGuy" <(E-Mail Removed)> wrote in message
> news:7F98D6F2-337A-4B7B-8698-(E-Mail Removed)...
> > Hi,
> > I am fairly new to Access Vbasic programming.
> >
> > What I am trying to do is have the 'Change Event' fire when
> > I enter any text into a text box. The 'Change Event' calls the
> > code but a problems arises when I start to look at the text entered.
> >
> > The problem seems to be that the text read in is alway 1 key stroke
> > behind what is in the text box. For example:
> > 1 - I enter "e" into the text box. The text box contains "e", but the code
> > detects
> > a null string when reading the text box contents
> > 2 - I then enter "f", now the text box contains "ef", but the code detects
> > only "e"
> > when reading the text box contents
> > 3 - I then enter "f", now the text box contains "eff", but the code
> > detects
> > only "ef"
> > when reading the text box contents
> >
> > What am I missing? Can any one shed some light on this?
> > Any help is greatly appreciated.
> >
> >
> >

>
>
>

 
Reply With Quote
 
=?Utf-8?B?Q2l0eUd1eQ==?=
Guest
Posts: n/a
 
      17th Mar 2006
Your suggestion works nicely. This leads to another question related to the
1st topic.

Now that I can process the actual text in the text box, I use that info to
find
a record in an underlying table. On the form I am using there is a list box
below
the text box. I want to see in the list box a high-lighted selection which
represents
the information found in the selected record in the underlying table.

How can I get the list box to highlight the record's information?



"Brendan Reynolds" wrote:

>
> Are you looking at the Text property or the Value property of the text box
> control? If you're referring to the control by name without specifying a
> specific property, you're looking at the Value property. Unlike VB controls,
> the Value property is the default property of an Access form control.
>
> The following code displays the text as I enter it ...
>
> Private Sub Text0_Change()
>
> Me.Label2.Caption = Me.Text0.Text
>
> End Sub
>
> --
> Brendan Reynolds
> Access MVP
>
> "CityGuy" <(E-Mail Removed)> wrote in message
> news:7F98D6F2-337A-4B7B-8698-(E-Mail Removed)...
> > Hi,
> > I am fairly new to Access Vbasic programming.
> >
> > What I am trying to do is have the 'Change Event' fire when
> > I enter any text into a text box. The 'Change Event' calls the
> > code but a problems arises when I start to look at the text entered.
> >
> > The problem seems to be that the text read in is alway 1 key stroke
> > behind what is in the text box. For example:
> > 1 - I enter "e" into the text box. The text box contains "e", but the code
> > detects
> > a null string when reading the text box contents
> > 2 - I then enter "f", now the text box contains "ef", but the code detects
> > only "e"
> > when reading the text box contents
> > 3 - I then enter "f", now the text box contains "eff", but the code
> > detects
> > only "ef"
> > when reading the text box contents
> >
> > What am I missing? Can any one shed some light on this?
> > Any help is greatly appreciated.
> >
> >
> >

>
>
>

 
Reply With Quote
 
=?Utf-8?B?Q2l0eUd1eQ==?=
Guest
Posts: n/a
 
      17th Mar 2006
I forgot to mention in this in my last post. Below is the code I use to read
in
the value entered into the text box.

strMatchText = Nz([Forms]![frmGetSubDivInfo]![txtMatchText].Text, "- - - - -")

When the form opens that contains the text box and list box, a new error
message
appears saying "Object doesn't support this property or method". Is the above
express causing this?

"Brendan Reynolds" wrote:

>
> Are you looking at the Text property or the Value property of the text box
> control? If you're referring to the control by name without specifying a
> specific property, you're looking at the Value property. Unlike VB controls,
> the Value property is the default property of an Access form control.
>
> The following code displays the text as I enter it ...
>
> Private Sub Text0_Change()
>
> Me.Label2.Caption = Me.Text0.Text
>
> End Sub
>
> --
> Brendan Reynolds
> Access MVP
>
> "CityGuy" <(E-Mail Removed)> wrote in message
> news:7F98D6F2-337A-4B7B-8698-(E-Mail Removed)...
> > Hi,
> > I am fairly new to Access Vbasic programming.
> >
> > What I am trying to do is have the 'Change Event' fire when
> > I enter any text into a text box. The 'Change Event' calls the
> > code but a problems arises when I start to look at the text entered.
> >
> > The problem seems to be that the text read in is alway 1 key stroke
> > behind what is in the text box. For example:
> > 1 - I enter "e" into the text box. The text box contains "e", but the code
> > detects
> > a null string when reading the text box contents
> > 2 - I then enter "f", now the text box contains "ef", but the code detects
> > only "e"
> > when reading the text box contents
> > 3 - I then enter "f", now the text box contains "eff", but the code
> > detects
> > only "ef"
> > when reading the text box contents
> >
> > What am I missing? Can any one shed some light on this?
> > Any help is greatly appreciated.
> >
> >
> >

>
>
>

 
Reply With Quote
 
=?Utf-8?B?Q2l0eUd1eQ==?=
Guest
Posts: n/a
 
      17th Mar 2006
Hi,

I found the source of the error, I was trying to repaint a label.
Sorry about that. But the high lighting a list box value still stands.

"Brendan Reynolds" wrote:

>
> Are you looking at the Text property or the Value property of the text box
> control? If you're referring to the control by name without specifying a
> specific property, you're looking at the Value property. Unlike VB controls,
> the Value property is the default property of an Access form control.
>
> The following code displays the text as I enter it ...
>
> Private Sub Text0_Change()
>
> Me.Label2.Caption = Me.Text0.Text
>
> End Sub
>
> --
> Brendan Reynolds
> Access MVP
>
> "CityGuy" <(E-Mail Removed)> wrote in message
> news:7F98D6F2-337A-4B7B-8698-(E-Mail Removed)...
> > Hi,
> > I am fairly new to Access Vbasic programming.
> >
> > What I am trying to do is have the 'Change Event' fire when
> > I enter any text into a text box. The 'Change Event' calls the
> > code but a problems arises when I start to look at the text entered.
> >
> > The problem seems to be that the text read in is alway 1 key stroke
> > behind what is in the text box. For example:
> > 1 - I enter "e" into the text box. The text box contains "e", but the code
> > detects
> > a null string when reading the text box contents
> > 2 - I then enter "f", now the text box contains "ef", but the code detects
> > only "e"
> > when reading the text box contents
> > 3 - I then enter "f", now the text box contains "eff", but the code
> > detects
> > only "ef"
> > when reading the text box contents
> >
> > What am I missing? Can any one shed some light on this?
> > Any help is greatly appreciated.
> >
> >
> >

>
>
>

 
Reply With Quote
 
Brendan Reynolds
Guest
Posts: n/a
 
      18th Mar 2006
A potential 'gotcha' to watch out for when using the Text property - you can
only use it when the control has the focus. This isn't a problem in the
Change event, as the control will have focus when that event fires, but it
can be confusing if you try to use the Text property in other events when
the control does not have focus.

Re highlighting an item in the listbox. For the purposes of this example,
I'm going to assume that this is not a multi-select listbox, and that the
bound column of the listbox matches the primary key field of the record.
Given those assumptions, here's an example using the Employees table from
the Northwind database. This example selects a record in the listbox
matching the 'last name' entered in the text box. 'Text0' is the name of the
textbox, and 'List2' is the name of the listbox.

Private Sub Text0_AfterUpdate()

Dim rst As ADODB.Recordset

Set rst = New ADODB.Recordset
With rst
.ActiveConnection = CurrentProject.Connection
.Source = "SELECT EmployeeID, LastName, FirstName " & _
"FROM Employees WHERE LastName = '" & _
Replace(Me.Text0, "'", "''") & "'"
.Open
If .BOF And .EOF Then
.Close
MsgBox "No match found."
Else
Me.List2 = .Fields("EmployeeID")
.Close
End If
End With

End Sub


--
Brendan Reynolds
Access MVP


"CityGuy" <(E-Mail Removed)> wrote in message
news:24171D44-85EE-4815-B3A7-(E-Mail Removed)...
> Your suggestion works nicely. This leads to another question related to
> the
> 1st topic.
>
> Now that I can process the actual text in the text box, I use that info to
> find
> a record in an underlying table. On the form I am using there is a list
> box
> below
> the text box. I want to see in the list box a high-lighted selection
> which
> represents
> the information found in the selected record in the underlying table.
>
> How can I get the list box to highlight the record's information?
>
>
>
> "Brendan Reynolds" wrote:
>
>>
>> Are you looking at the Text property or the Value property of the text
>> box
>> control? If you're referring to the control by name without specifying a
>> specific property, you're looking at the Value property. Unlike VB
>> controls,
>> the Value property is the default property of an Access form control.
>>
>> The following code displays the text as I enter it ...
>>
>> Private Sub Text0_Change()
>>
>> Me.Label2.Caption = Me.Text0.Text
>>
>> End Sub
>>
>> --
>> Brendan Reynolds
>> Access MVP
>>
>> "CityGuy" <(E-Mail Removed)> wrote in message
>> news:7F98D6F2-337A-4B7B-8698-(E-Mail Removed)...
>> > Hi,
>> > I am fairly new to Access Vbasic programming.
>> >
>> > What I am trying to do is have the 'Change Event' fire when
>> > I enter any text into a text box. The 'Change Event' calls the
>> > code but a problems arises when I start to look at the text entered.
>> >
>> > The problem seems to be that the text read in is alway 1 key stroke
>> > behind what is in the text box. For example:
>> > 1 - I enter "e" into the text box. The text box contains "e", but the
>> > code
>> > detects
>> > a null string when reading the text box contents
>> > 2 - I then enter "f", now the text box contains "ef", but the code
>> > detects
>> > only "e"
>> > when reading the text box contents
>> > 3 - I then enter "f", now the text box contains "eff", but the code
>> > detects
>> > only "ef"
>> > when reading the text box contents
>> >
>> > What am I missing? Can any one shed some light on this?
>> > Any help is greatly appreciated.
>> >
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?Q2l0eUd1eQ==?=
Guest
Posts: n/a
 
      20th Mar 2006
Thanks for the tip I 'll look into it

"Brendan Reynolds" wrote:

> A potential 'gotcha' to watch out for when using the Text property - you can
> only use it when the control has the focus. This isn't a problem in the
> Change event, as the control will have focus when that event fires, but it
> can be confusing if you try to use the Text property in other events when
> the control does not have focus.
>
> Re highlighting an item in the listbox. For the purposes of this example,
> I'm going to assume that this is not a multi-select listbox, and that the
> bound column of the listbox matches the primary key field of the record.
> Given those assumptions, here's an example using the Employees table from
> the Northwind database. This example selects a record in the listbox
> matching the 'last name' entered in the text box. 'Text0' is the name of the
> textbox, and 'List2' is the name of the listbox.
>
> Private Sub Text0_AfterUpdate()
>
> Dim rst As ADODB.Recordset
>
> Set rst = New ADODB.Recordset
> With rst
> .ActiveConnection = CurrentProject.Connection
> .Source = "SELECT EmployeeID, LastName, FirstName " & _
> "FROM Employees WHERE LastName = '" & _
> Replace(Me.Text0, "'", "''") & "'"
> .Open
> If .BOF And .EOF Then
> .Close
> MsgBox "No match found."
> Else
> Me.List2 = .Fields("EmployeeID")
> .Close
> End If
> End With
>
> End Sub
>
>
> --
> Brendan Reynolds
> Access MVP
>
>
> "CityGuy" <(E-Mail Removed)> wrote in message
> news:24171D44-85EE-4815-B3A7-(E-Mail Removed)...
> > Your suggestion works nicely. This leads to another question related to
> > the
> > 1st topic.
> >
> > Now that I can process the actual text in the text box, I use that info to
> > find
> > a record in an underlying table. On the form I am using there is a list
> > box
> > below
> > the text box. I want to see in the list box a high-lighted selection
> > which
> > represents
> > the information found in the selected record in the underlying table.
> >
> > How can I get the list box to highlight the record's information?
> >
> >
> >
> > "Brendan Reynolds" wrote:
> >
> >>
> >> Are you looking at the Text property or the Value property of the text
> >> box
> >> control? If you're referring to the control by name without specifying a
> >> specific property, you're looking at the Value property. Unlike VB
> >> controls,
> >> the Value property is the default property of an Access form control.
> >>
> >> The following code displays the text as I enter it ...
> >>
> >> Private Sub Text0_Change()
> >>
> >> Me.Label2.Caption = Me.Text0.Text
> >>
> >> End Sub
> >>
> >> --
> >> Brendan Reynolds
> >> Access MVP
> >>
> >> "CityGuy" <(E-Mail Removed)> wrote in message
> >> news:7F98D6F2-337A-4B7B-8698-(E-Mail Removed)...
> >> > Hi,
> >> > I am fairly new to Access Vbasic programming.
> >> >
> >> > What I am trying to do is have the 'Change Event' fire when
> >> > I enter any text into a text box. The 'Change Event' calls the
> >> > code but a problems arises when I start to look at the text entered.
> >> >
> >> > The problem seems to be that the text read in is alway 1 key stroke
> >> > behind what is in the text box. For example:
> >> > 1 - I enter "e" into the text box. The text box contains "e", but the
> >> > code
> >> > detects
> >> > a null string when reading the text box contents
> >> > 2 - I then enter "f", now the text box contains "ef", but the code
> >> > detects
> >> > only "e"
> >> > when reading the text box contents
> >> > 3 - I then enter "f", now the text box contains "eff", but the code
> >> > detects
> >> > only "ef"
> >> > when reading the text box contents
> >> >
> >> > What am I missing? Can any one shed some light on this?
> >> > Any help is greatly appreciated.
> >> >
> >> >
> >> >
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
apply cell change event to single column - WorksheetChange Event MiataDiablo@gmail.com Microsoft Excel Programming 5 4th May 2008 03:28 AM
Problem with CommandBarComboBox Change Event (Event fires only once) M. Khalid Farooq Microsoft Outlook Interoperability 6 23rd Oct 2006 10:44 AM
Control where change event does not trigger click event? =?Utf-8?B?c3dvcmRmaXNo?= Microsoft Powerpoint 2 17th Jul 2006 07:21 PM
MsgBox in Enter event causes combobox not to run Change event =?Utf-8?B?UmljaGFyZA==?= Microsoft Excel Programming 0 6th Mar 2006 03:52 PM
Datagrid cell change event? Where to find event. Roger Microsoft VB .NET 4 29th Mar 2005 10:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:33 PM.