I get a "#Name?" when setting a defaultvalue

lvr

New member
Local time
Today, 14:33
Joined
Aug 22, 2008
Messages
9
Hello,

I'm setting with vba the default values of the fields of my form.
For some fields, I don't get the default value but a "#Name?" instead.
As soon as I start editing the record (by typing some text in another field), the "#Name?" is changed to the default value of the field as set in the table. So the default value set by code is completely ignored !

Here is how I set the default value:
Code:
sfrm.txtItineraire.DefaultValue = "DefaultValue" 'Me.txtItinéraire
Rem: Here it is on subform, but the same occurs for a field on the main form too.

Any idea how to get it work ?

Thanks,

Laurent


PS: If no default value in the table, then the "#Name?" changes into a blank field.
 
If you want to show the user "DefaultValue" in the textBox then use
sfrm.txtItineraire = "DefaultValue" 'Me.txtItinéraire

Regards
 
Thanks Terry, but I want it to be the default value. What you suggest would start the editing of the record and this is not what I want.
 
The #Name is probably coming from the control not being able to see the data field. Either your form is unbound or you do not have that field in the recordset (table, query, etc) for the form. It goes away when the default value is assigned because it is treating it as an unbound control.

Why not set the default value in the Default Value properties of the control itself instead of doing it in code?

-dK
 
Hello,

I'm setting with vba the default values of the fields of my form.
For some fields, I don't get the default value but a "#Name?" instead.
As soon as I start editing the record (by typing some text in another field), the "#Name?" is changed to the default value of the field as set in the table. So the default value set by code is completely ignored !

Here is how I set the default value:
Code:
sfrm.txtItineraire.DefaultValue = "DefaultValue" 'Me.txtItinéraire
Rem: Here it is on subform, but the same occurs for a field on the main form too.

Any idea how to get it work ?

Thanks,

Laurent


PS: If no default value in the table, then the "#Name?" changes into a blank field.

From access help :

In Visual Basic, use a string expression to set the value of this property. For example, the following sets the DefaultValue property for a text box control named PaymentMethod to "Cash":

Forms!frmInvoice!PaymentMethod.DefaultValue = """Cash"""Note To set this property for a field by using Visual Basic, use the ADO DefaultValue or use the DAO DefaultValue property.
 
the best way to set this property is in the property Sheet for the textbox. Data tab, Default Value.
 
Ron_dk is correct. I have tested and used
sfrm.txtItineraire.DefaultValue = "'DefaultValue'"

Single quotes within the double-quotes.
 
Thanks guys. It works fine.
I'm just surprised that this doesn't seems to required all the time.
For example this works fine:
Code:
 frm.lstPointA.DefaultValue = Me!idPointA
 
For example this works fine:
Code:
frm.lstPointA.DefaultValue = Me!idPointA
Of course it works !!! The second example is numerical.
 

Users who are viewing this thread

Back
Top Bottom