I truly appreciate the help, but you completely confused me. I am not a
VB
programmer, and I have no idea what you are saying. I don't know where
the
Before Insert event is located, I only see Before Update. And you are
correct in thinking that I don't want the user to edit the name, but how
do I
protect the field so it cannot be changed?
The before insert only exists for the whole form, not a particular control.
Note that the controls, and even the forms header, and even the "detail"
section of a form has all kinds of properties. If you click on a blank area
in the forms section (in design mode), you have selected the detail section.
To correct see the "forms" properties, then you need to select the form. I
usually with the mouse click on the upper left "square" of the form, but you
can also go edit->select form.
The above is quite easy to mess up, and get confused over. When I talked
about the forms "before insert" event, you must select the "form" as
outlined above to get to these events. As I mentioned, using the before
insert is a good event, since then if the user exits the form, a blank
record will NOT be crated. Do note that if you set the "default" for a
record, then again you should be able to "exit" without a record being
added.
Additionally, if the user decides to exit out of the form without saving
anything entered, i.e. changes his/her mind, how is this done? Currently
I
have two buttons, Exit and Save Form. If the user intends to save the
form,
they should press Save Form. If the user wants to exit without saving the
form, they should press Exit. However, when pressing Exit, a record is
created in the database.
If the user has done nothing, then a blank record should NOT get added. It
is possible that by programmatic setting the default for a control, then you
might "dirty" a record. Remember, when you exit a form, no prompts occur,
and saving is automatic. So, as a general rule, if a user enters some data,
and close the form, then data is saved. However, if the user is on a new
blank record, and does not edit (we call this "dirty") the form, then
closing should not add the blank record (however, code that runs and sets
values can often cause the record to be dirtied, and that means exiting will
write the record).
however, note that I did say in place of trying to use that code in the
form, that you can simply put the function name DIRECTLY into the controls
default value.
that means you select the "username" control (I don't know the name you
used). and then on the properties sheet for that control, you can put the
function name as the default as follows:
I quote from my past post:
<quote>
And, note that you actually put the function name in the controls default
setting, and use no code at all
=fOsUserName()
<quote>
And, did mention that this would be likely the most easy approach here. So,
the above is now talking about NOT using the forms before insert event, but
simply setting the controls default.
Get the above working, and then start the next task of NOT allowing the user
to edit that control....
(hint: you should be able to set the controls "locked" setting on the "data"
tab of the properties sheet)
However, when pressing Exit, a record is
created in the database. How do I handle this situation?
As mentioned, if the user edited the record, then it will be saved for you
do NOT need a save button. You could start writing code to handle this, but
no code at all is really needed here (this issue of save prompts is a
different issue then setting up the default values.
Virtually all commercial databases for the last 20 years don't prompt to
save. If you don't want to save the data, either delete the record, or go
edit->undo.
You can start writing code to override this behavior, but it is work that
generally gives little, or no benefits to your application...