Email Address Calc as a Default Value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm sure this question has been asked a thousand times before so please
excuse me if you have read it already.

I have a table setup to list our employees It has Values of "FirstName" and
"LastName" and one for "email" The email/username is made of the 1st letter
of the first name and the whole last name. I made this function that works
great as and update query and I can make a button on a form to trigger this
query but it there anyway that I can put a funtion like this into the default
value in the "email" field? Or is there a way in the form itself to do
something to this? I'd like to get it into the table itself so it'll carry
over and also in case people start to data enter without using the form. The
other reason I want to do this is because there are a few people that do have
different usernames than the cookie cutter formula and I would like to change
them once and not have to go back everytime I hit the query button and change
their emails in the database.

LCase(Left$(Employees!FirstName,1)+Employees!LastName)
 
The email/username is
made of the 1st letter of the first name and the whole last name. I
made this function that works great as and update query

Not a great idea: when Betty Jeeves comes back from honeymoon as the new
Mrs Evans, there will be a great deal to do in order to create a new
email address. What if she wants to keep bjeeves rather than bevans?
Or is there a way in the form itself to do something to this?

In my view, that is the better way to do it. Use the Form_BeforeUpdate
event do do something like

If Isnull(txtUserName) Then
' no existing text, create a new default username
txtUserName = LCase$(Left$(txtFirstName,1) & txtLastName)

Else
' there's something there, so don't mess it up
' no harm in reformatting it into LCase
txtUserName = LCase$(txtUserName)

End If
in case people start to data enter without using the form.

In that case a form-based solution won't work; theoretically a db trigger
would manage this but they are not available in Access.
reason I want to do this is because there are a few people that do
have different usernames than the cookie cutter formula and I would
like to change them once and not have to go back everytime

Exactly.

Hope that helps


Tim F
 
Back
Top