When/how to invoke the VB Code

  • Thread starter Thread starter Daise
  • Start date Start date
D

Daise

I have a form/sfm...based on a selection I display
certain records in the subform. Users have option to
edit the data they see or they can Add a new record..

If they choose to Add a new record, I want to control the
data for the couple of fields. E.g. FullName =
Concatenate the First and the Last name entered by the
user. At what point do I concatenate the names into the
FullName field? i.e. at what property do I put my
VBCode?

secondly, I only want to do this when a user is entering
a NEW record and not updating an existing record. What
do I need to do to ensure this?

Thanks much!!
-D

Ps...I posted the message to the wrong section
earlier....apologize if you are wondering why you are
seeing it in two places..
 
Hi there!
-----Original Message-----
If they choose to Add a new record, I want to control the
data for the couple of fields. E.g. FullName =
Concatenate the First and the Last name entered by the
user. At what point do I concatenate the names into the
FullName field? i.e. at what property do I put my
VBCode?

I usually like to do this on the OnEnter event of the
FullName field
secondly, I only want to do this when a user is entering
a NEW record and not updating an existing record. What
do I need to do to ensure this?

If IsEmpty(Fullname) OR IsNull(FullName) then
FullName = Firstname & " " & UCase$(Lastname)
End If

:-)

Note: I always like to check for both IsEmpty and IsNull,
because you never know what the database will kick up.
Also, always check for IsNull last, because Access
evaluates OR statements right-to-left, and IsEmpty will
throw up an error if you give it a Null value.

Rgds,
Greg
 
I have a form/sfm...based on a selection I display
certain records in the subform. Users have option to
edit the data they see or they can Add a new record..

If they choose to Add a new record, I want to control the
data for the couple of fields. E.g. FullName =
Concatenate the First and the Last name entered by the
user. At what point do I concatenate the names into the
FullName field? i.e. at what property do I put my
VBCode?

In the AfterUpdate event of the first name field, & also of the last name
field, put something like:

me![FullName] = trim (me![FirstName] & " " & me![LastName])

secondly, I only want to do this when a user is entering
a NEW record and not updating an existing record

Why? If they can edit the first or last name fields, you should recalculate
the full name field. If they can *not* edit those fields, their AfterUpdate
events will not fire for existing records!

What do I need to do to ensure this?

"me.newrecord" (without the quotes) is True if the record is new, False if
it already exists (ie. has already been saved).


HTH,
TC
 
Greg, a few caveats (provided in-line).

TC


Greg Bromage said:
Hi there!


I usually like to do this on the OnEnter event of the FullName field

Not a good place - for two reasons.

(1) Say he is positioned on a blank new record. Your suggestion will dirty
the record as soon as he tabs into the FullName field - even if he has not
entered anything yet. For a UI viewpoint, that is not appropriate.

(2) What if he does not go into the FullName field at all? Your suggestion
will leave the FullName field unprocessed.

AfterUpdate of the first & last name fields, is the way to go. :-)

If IsEmpty(Fullname) OR IsNull(FullName) then
FullName = Firstname & " " & UCase$(Lastname)
End If

But what if he enters a first & last name, tabs into the fullname field,
then goes back (before he has saved the record) & amends the first or last
name field(s)? (Perhaps he made a spelling error.) You must recalculate the
FullName field in that scenario. Again, AfterUpdate of the first & last name
fields is the way to go.
 
Back
Top