Set Default Value... From A Form

oneilldm

Registered User.
Local time
Yesterday, 21:04
Joined
Dec 10, 2008
Messages
19
I'd like to set default value for a field in a table from a form.

I tried:

MyTable!MyField!DefaultValue = Me.myLastName

But it's telling me "Object Required".

I must not be going about this in the right way.

I have a simple form that uses this table. When the user creates a new record I want it to automatically enter their last name.

Thanks
 
you cant set a default value for a field, you can SET the value using some coding

I'm sensing some design issues here:
does the user enter their last name everytime they create a record?
 
You can probably set it, but I think you'd have to use DAO/TableDef. It's more common to set the default value property of the control on the form that's bound to that field.
 
Thank you for the replies!

I should probably back-up a little bit.

What I really want to do is automatically enter the last name of the User creating a new record.

This form is just a log of numbers and descriptions with the user name that entered the record and a date.

I capture the user name to a public variable when they first start up the program.

My first attempt... when the user first gave focus to a new, blank field... it would just insert the value into the Issuer field.

If IsNull(Me.Log_Number.Value) And IsNull(Me.Issuer.Value) Then
Me.Issuer.Value = Me.myLastName

But then a record was being created even if the user bailed out.

So... I'm looking for a good way to have that field value ready to go if I have a legit record.

Thanks again!
 
Since you can't refer to a public variable outside VBA, create a public function in a standard module that returns the value of your variable. In the default value property of the field or control, try:

=FunctionName()

Can't think right off if it will want the equals sign or not, so try it both ways if it doesn't work at first.
 
How do you legit a field? if you can determine is not legit, then insert a Me.Undo. This should work.
 

Users who are viewing this thread

Back
Top Bottom