Get #name? when assigning string to defaultvalue

R

RV55

I'm trying to increment the default value of a text box in a subform.
Although everything seems right I keep getting #name?.

This is what I did;
1. Created 2 linked tables- AssetDB and AssetGroupsDB.
Every record in AssetDB belongs to 1 of the groups set up in AssetGroupsDB.
2. Created a form "Asset Group Management" that shows the AssetGroupsDB
details on the top half and the matching AssetDB records on the bottom half
in a datasheet format.
3. Creted the following code the the "On Enter" event proceedure for the
subform.
Forms![Asset Group Management]![AssetsDB
Subform].Form![AssetID].DefaultValue = "V" & Format((Right(DMax("AssetID",
"AssetsDB"), 5) + 1), "00000")
This should assign a default of a 6 character string starting with "V" and
ending with an incremented 5 digit number.

When I change focus to the subform the default value changes to #name?.

Things I've tried;
Putting the right side of the equation in a msgbox- it show "V00003" so the
right side is ok.
Tried to assign just "V00003"- I still get #name?.
Assigning a number- it works so the left side of the equation is ok.

Seems like it just wont take stings.

Any ideas?
 
A

Arvin Meyer [MVP]

First thing to do when you get a #Name error is to check for Missing
References. From any code window:

Tools >>> References
 
R

RV55

Arvin Meyer said:
First thing to do when you get a #Name error is to check for Missing
References. From any code window:

Tools >>> References
--

Oh ok. Which references do I need to assign strings to defaultvalue?
 
K

Ken Snell \(MVP\)

A DefaultValue string must be surrounded by " characters:

Forms![Asset Group Management]![AssetsDB
Subform].Form![AssetID].DefaultValue = """V" & Format((Right(DMax("AssetID",
"AssetsDB"), 5) + 1), "00000") & """"
 
R

RV55

That's the answer! I knew it would be something simple.

So thw quotes have to be part of the string. = "V00003" wont work but
"""V00003""" will.

Seems a bit unusual to have to include the quotes in the string but there
you go.

Thank you Ken.
 
K

ken

Its because the DefaultValue property of a control is always a string
expression regardless of the data type of the underlying field. In
effect all its doing is pushing a string of characters into the
control. In many cases it doesn't matter if you omit the literal
quotes, but often it does, as you've found out, so its best to always
include them. An interesting example of when its necessary is with a
control bound to a date/time data type. Lets say you want to set the
default value for the next record to a date entered in the current
record; you'd put this in the form's AfterUpdate event procedure:

Me.MyDate.DefaultValue = """" & Me.MyDate & """"

If the date you'd just entered was today, 02/22/2009 (in US format)
then without the literal quotes this would be interpreted as an
arithmetical expression, which happens to evaluate to
0.0000452509163310557. Now because Access stores date/time values as
64 bit floating point number as an offset from 30 December 1899
00:00:00, with the integer part representing the day and the
fractional part the time of day, this number corresponds to the date/
time value of 30 December 1899 00:00:04, so instead of today's date
you'd get that date/time in the next new record.

You can see this for yourself by entering the following in the debug
window:

? Format(02/22/2009,"dd mmmm yyyy hh:nn:ss")

Sometimes people will use the # date delimiter instead of quotes
around the value:

Me.MyDate.DefaultValue = "#" & Me.MyDate & "#"

Don't do this. It will enter the value as a date, but if used here in
Yurp would change 4 July to 7 April because a date literal delimited
with # characters expects the US short date format mm/dd/yyyy or an
otherwise internationally unambiguous format (the ISO format of YYYY-
MM-DD is best when using a date literal) whereas we use dd/mm/yyyy
here.

Ken Sheridan
Stafford, England

That's the answer! I knew it would be something simple.

So thw quotes have to be part of the string. = "V00003" wont work but
"""V00003""" will.

Seems a bit unusual to have to include the quotes in the string but there
you go.

Thank you Ken.

Ken Snell (MVP) said:
A DefaultValue string must be surrounded by " characters:
Forms![Asset Group Management]![AssetsDB
Subform].Form![AssetID].DefaultValue = """V" & Format((Right(DMax("AssetID",
"AssetsDB"), 5) + 1), "00000") & """"
 

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