On Change Bug?

  • Thread starter Ivan R via AccessMonster.com
  • Start date
I

Ivan R via AccessMonster.com

Okay I have a form whose caption is based on some information on the form.
The information updates the caption at every change. For example the caption
at a new record will read "Background Analysis Database", however when there
is information entered for a specific record, the database will change the
caption to "Background Check for LastName, FirstName Middlename". My problem
or bug appears when I start to change the FirstName field. There is code
behind the fields that will automatically update the caption at each change
for the field, however on the FirstName field when you first enter the first
change, the first letter is selected and over written, the user then has to
go back over and retype the first letter or it causes them to be off by one
letter. The code I have entered in the background goes as follows, and it is
entered in the On Change event:

DoCmd.RunCommand acCmdSaveRecord
UpdateCaption

UpdateCaption is a small module which saves me some typing it goes like this:

Dim fstname, lstname, midname, Name As String
fstname = Forms![main form]![applicant firstname]
lstname = Forms![main form]![Applicant LastName]
midname = Forms![main form]![Applicant MiddleName]
Name = lstname & ", " & fstname & " " & midname
Me.Caption = "Background Check for " & Name

Any help or suggestions would be appreciated.
 
J

Jeff Boyce

Ivan

I don't know if it will make a difference in what you are seeing, but...

The word "Name" is a reserved word in Access. You are using it in your
code. Access may be confused as to just what you are referring to. Try
changing that to PersonName...

Regards

Jeff Boyce
<Office/Access MVP>
 
L

Larry Linson

The OnChange event fires for every keystroke of the Control. I really doubt
that is the event to which you want to respond. I suspect you really want to
change the caption only when you have all three, First/Middle/Last names
entered. I am also not sure I can see a "business purpose" for changing the
caption, unless you are likely to have multiple copies of the same form
open, and some minimized. The caption isn't really a very convenient place
to have changeable data.

But, assuming there is a reason to change the caption, my suggestion would
be to call the same procedure from the AfterUpdate event of each of the name
fields, check that all three have been entered, and then execute the code
you show. Assuming you'll be using the same or similar form to edit the
records, put the code in the Current event, as well, so the caption will
reflect the person whose data is being edited, as well.

Larry Linson
Microsoft Access MVP
 
J

John Vinson

Me.Caption = "Background Check for " & Name

Any help or suggestions would be appreciated.

I'd suggest not using the caption property AT ALL: instead, put a
textbox on the form with a Control Source of the concatenation
expression.

John W. Vinson[MVP]
 
D

Dirk Goldgar

Ivan R via AccessMonster.com said:
Okay I have a form whose caption is based on some information on the
form. The information updates the caption at every change. For
example the caption at a new record will read "Background Analysis
Database", however when there is information entered for a specific
record, the database will change the caption to "Background Check for
LastName, FirstName Middlename". My problem or bug appears when I
start to change the FirstName field. There is code behind the fields
that will automatically update the caption at each change for the
field, however on the FirstName field when you first enter the first
change, the first letter is selected and over written, the user then
has to go back over and retype the first letter or it causes them to
be off by one letter. The code I have entered in the background goes
as follows, and it is entered in the On Change event:

DoCmd.RunCommand acCmdSaveRecord
UpdateCaption

I really don't think you want to save the record every time the user
types a new letter in the text box. That may be causing the odd
selection behavior you're seeing, and it doesn't really make sense
anyway.
 
I

Ivan R via AccessMonster.com

Thansk Jeff.

I changed the Name variable to wholeName, however it is still exhibiting this
odd behaviour. If you have any other suggestions I would like to hear them.

Jeff said:
Ivan

I don't know if it will make a difference in what you are seeing, but...

The word "Name" is a reserved word in Access. You are using it in your
code. Access may be confused as to just what you are referring to. Try
changing that to PersonName...

Regards

Jeff Boyce
Okay I have a form whose caption is based on some information on the form.
The information updates the caption at every change. For example the
[quoted text clipped - 31 lines]
Any help or suggestions would be appreciated.
 
I

Ivan R via AccessMonster.com

The only reason that i will not use the code on the afterupdate event is that
I want the name in the caption to change as the user types the information
into the database, if I do it in the afterupdate event it will not make the
change until the record is complete or you add a new record. I did try the
code there first, it just didn't have the effect that I wanted and the whole
reason for doing this on this event is the effect, which is the changing of
the name as you go. I know it is probably not really a pressing and urgent
issue, but I think it is a cool effect and if it all possible I would like to
keep it...

The code right now is in the CurrentEvent of the form and on the OnChange
event of the fields that are used to change the caption.

Larry said:
The OnChange event fires for every keystroke of the Control. I really doubt
that is the event to which you want to respond. I suspect you really want to
change the caption only when you have all three, First/Middle/Last names
entered. I am also not sure I can see a "business purpose" for changing the
caption, unless you are likely to have multiple copies of the same form
open, and some minimized. The caption isn't really a very convenient place
to have changeable data.

But, assuming there is a reason to change the caption, my suggestion would
be to call the same procedure from the AfterUpdate event of each of the name
fields, check that all three have been entered, and then execute the code
you show. Assuming you'll be using the same or similar form to edit the
records, put the code in the Current event, as well, so the caption will
reflect the person whose data is being edited, as well.

Larry Linson
Microsoft Access MVP
Okay I have a form whose caption is based on some information on the form.
The information updates the caption at every change. For example the
[quoted text clipped - 31 lines]
Any help or suggestions would be appreciated.
 
I

Ivan R via AccessMonster.com

I tried it without saving the record and if it is not included, then the
caption is not updated at every stroke. The odd behavior also is only on
the first letter entered, once the record is created I can go back delete
everything and start all over without the behaviour at all. Do you think
that it could be an issue with the record being created? I have some code
that is executed the minute that the record is created. It then causes the
form to repaint...I think this is my problem, huh?

Dirk said:
Okay I have a form whose caption is based on some information on the
form. The information updates the caption at every change. For
[quoted text clipped - 12 lines]
DoCmd.RunCommand acCmdSaveRecord
UpdateCaption

I really don't think you want to save the record every time the user
types a new letter in the text box. That may be causing the odd
selection behavior you're seeing, and it doesn't really make sense
anyway.
 
I

Ivan R via AccessMonster.com

I have found out what my problem was. I had some code in the PK field which
repainted the form on change from null to the next number. The second that
the user typed a letter into any field, which spawned a change in the primary
key, the form was repainted, causing the selection of the first field with
any data entered, in this instance the first letter of the first name field.
I figured that I did not need the code on the primary key field and so I
changed it to the afterupdate event of the first field, now it works great!

Ivan said:
I tried it without saving the record and if it is not included, then the
caption is not updated at every stroke. The odd behavior also is only on
the first letter entered, once the record is created I can go back delete
everything and start all over without the behaviour at all. Do you think
that it could be an issue with the record being created? I have some code
that is executed the minute that the record is created. It then causes the
form to repaint...I think this is my problem, huh?
[quoted text clipped - 6 lines]
selection behavior you're seeing, and it doesn't really make sense
anyway.
 
L

Larry Linson

As was pointed out more politely by others -- however "cool" you may think
the effect, changing the caption of the form is, at best, an "unusual and
unfamiliar" interface feature -- there are other, simpler,
less-disturbing-to-the-user approaches to showing what record is being
edited. One of those would be to display the information in large
characaters in the Form's Header... the information could be displayed in a
Label or a Text Box.

Please note that I suggested the AfterUpdate event of the Control into which
you are typing, not the Form's AfterUpdate, if you feel compelled to submit
your users to the unfamiliar UI. The Record is not, at least not
necessarily, saved before the Control's AfterUpdate.

Just for the record: my clients always wanted to insulate their users from
"unusual and unfamiliar" interface features, because they had to figure out
what was going on, and it caused a negative impact to their employees'
productivity.

Larry Linson
Microsoft Access MVP


Ivan R via AccessMonster.com said:
The only reason that i will not use the code on the afterupdate event is
that
I want the name in the caption to change as the user types the information
into the database, if I do it in the afterupdate event it will not make
the
change until the record is complete or you add a new record. I did try
the
code there first, it just didn't have the effect that I wanted and the
whole
reason for doing this on this event is the effect, which is the changing
of
the name as you go. I know it is probably not really a pressing and
urgent
issue, but I think it is a cool effect and if it all possible I would like
to
keep it...

The code right now is in the CurrentEvent of the form and on the OnChange
event of the fields that are used to change the caption.

Larry said:
The OnChange event fires for every keystroke of the Control. I really
doubt
that is the event to which you want to respond. I suspect you really want
to
change the caption only when you have all three, First/Middle/Last names
entered. I am also not sure I can see a "business purpose" for changing
the
caption, unless you are likely to have multiple copies of the same form
open, and some minimized. The caption isn't really a very convenient place
to have changeable data.

But, assuming there is a reason to change the caption, my suggestion would
be to call the same procedure from the AfterUpdate event of each of the
name
fields, check that all three have been entered, and then execute the code
you show. Assuming you'll be using the same or similar form to edit the
records, put the code in the Current event, as well, so the caption will
reflect the person whose data is being edited, as well.

Larry Linson
Microsoft Access MVP
Okay I have a form whose caption is based on some information on the
form.
The information updates the caption at every change. For example the
[quoted text clipped - 31 lines]
Any help or suggestions would be appreciated.
 
I

Ivan R via AccessMonster.com

Thank you,

I will keep this in mind. I had not thought about adding the information to
the form header, you are right that is a good spot to put important
information.

Thanks

Larry said:
As was pointed out more politely by others -- however "cool" you may think
the effect, changing the caption of the form is, at best, an "unusual and
unfamiliar" interface feature -- there are other, simpler,
less-disturbing-to-the-user approaches to showing what record is being
edited. One of those would be to display the information in large
characaters in the Form's Header... the information could be displayed in a
Label or a Text Box.

Please note that I suggested the AfterUpdate event of the Control into which
you are typing, not the Form's AfterUpdate, if you feel compelled to submit
your users to the unfamiliar UI. The Record is not, at least not
necessarily, saved before the Control's AfterUpdate.

Just for the record: my clients always wanted to insulate their users from
"unusual and unfamiliar" interface features, because they had to figure out
what was going on, and it caused a negative impact to their employees'
productivity.

Larry Linson
Microsoft Access MVP
The only reason that i will not use the code on the afterupdate event is
that
[quoted text clipped - 44 lines]
 

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

Top