User Sets Control Default Value

J

JPC

I would like my user to be able to set and lock default values for controls
in a data entry form so that repeated information is entered automatically.
I have a form that asks the user to enter data into a control. A command
button then runs code that sets the default value
[Me.ControlName.DefaultValue = Me.ControlName], and disables the control
[Enabled = False, Locked = True]. As long as the data contains numerals
only, it works just fine. If the data entered contains anything else, like
letters, spaces, or a hyphen, it doesn’t work correctly.

In the table design, this is a text field. Entering data directly into the
table works, as does a straight data entry form, without default values etc.
However when I insert the code for setting default values and disabling the
control, I am having problems.

In the form, if the user enters ABC-123 into the control, then clicks the
command button, the original entry is intact, and the control does get
disabled. But #Name? starts to display in the control for a new record. As
additional entries are made, the control for this field is left blank, and
#Name? appears to move down, and continues to display in the control for new
records. In the table, the original user entry of ABC-123 is saved in the
field for the first record entry only. This field is blank for additional
entries.

Any suggestions?
 
D

Dirk Goldgar

JPC said:
I would like my user to be able to set and lock default values for controls
in a data entry form so that repeated information is entered
automatically.
I have a form that asks the user to enter data into a control. A command
button then runs code that sets the default value
[Me.ControlName.DefaultValue = Me.ControlName], and disables the control
[Enabled = False, Locked = True]. As long as the data contains numerals
only, it works just fine. If the data entered contains anything else,
like
letters, spaces, or a hyphen, it doesn’t work correctly.

In the table design, this is a text field. Entering data directly into
the
table works, as does a straight data entry form, without default values
etc.
However when I insert the code for setting default values and disabling
the
control, I am having problems.

In the form, if the user enters ABC-123 into the control, then clicks the
command button, the original entry is intact, and the control does get
disabled. But #Name? starts to display in the control for a new record.
As
additional entries are made, the control for this field is left blank, and
#Name? appears to move down, and continues to display in the control for
new
records. In the table, the original user entry of ABC-123 is saved in the
field for the first record entry only. This field is blank for additional
entries.

Force quotes around the DefaultValue setting:

Me.ControlName.DefaultValue = _
Chr(34) & Me.ControlName & Chr(34)
 

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