Text Box Defaults

S

Steve

Hi,
Im trying to set a text box Default Value to a public variable in my database
I have set the Default Value to = MyVariable(60) but all I get is #Name?
the variable is a variant and I have checked to see that whats stored in
the variable can be entered into the text box.
Help!
Steve - Land Down Under
 
S

Steve Schapel

Steve,

Is MyVariable the name of a Function? If so, I would expect it to work
as the textbox's Default Value, as long as its syntax is correct.

I would suspect that the #Name? error may not be related at all to this
Default Value property. It is more likely to be related to the Control
Source property, or the name of the control. Can you check that:
- the Control Source of the textbox is set to the correct name of a
field in the form's underlying table/query.
- the Name of the textbox is the same as the name of the field it is
bound to, or if not:
- it is not the same as the name of any other field in the form's
underlying table/query.
 
S

Steve

Thanks Steve
The text box name is correct and is in the list presented when you click on
the field list next to Control Source.
the variable is just a public variable not a function
maybe I can call a funtion to give the variable but that sort of defeats the
object of having a public variable dont it.
If i type in =4110 manualy into the text boxes Default Value then every new
record shows 41110 so why doesnt a public variable called MyVariable(60)
which has a value of 4110 work here.
I will try a function and see if that works as per your sugestion
Thanks for your valuable time I do apreciate all the help I can muster
 
S

Steve Schapel

Steve,

I'm afraid I'm not really sure what you mean by a "public variable".
There are variables which can be declared and have a value assigned
within VBA procedures or modules, but in that case they only exist
within the context of VBA, and have no meaning outside that context, so
could not be applied to a form or control property. Then there are
variables that are created, only in Access 2007, using the SetTempVar
macro action, and these variables can be used more widely, but have to
be properly referenced as being part of the TempVars collection. So I
would expect in your case that a user-defined function will be the way
to go.
 
S

Steve

If I set the Defalt value of the text box to a function =DefValue(60)
Public Function DefValue(v As Variant)
DefValue = Deft(v) 'Deft(60) is a Public Variable with an array
End Function
then it works just fine as you suggested
but it sort of deafeats the object of having a public variable if you have
to use a function to get at it.
= Deft(60) does not seem to work and so I guess its just an Access thing.
 
S

Steve

Steve
This is from the help file press f1
Quote "the Public statement at the module level (General section) of a
standard module to explicitly declare variables as public; that is, they are
available to all procedures in all modules"

So am I to belive that the public statement has no affect on a text box.
I was thinking the default value of a text box can be changed with a
procedure and therefore is subject to Public variables.
Seems I had read it all wrong
Thanks Steve
Im going to rest now my head hurts LOL
 
S

Steve Schapel

Steve,

The key phrase in the quoted text is: "they are available to all
procedures in all modules."

The property of a control on a form is outside this scope.

It gets confusing, perhaps, when you then consider that the value of the
property can be manipulated via a VBA procedure. For example, within
the form's module you could use code like this:
Me.MyTextbox.DefaultValue = Deft(60)
.... but you see the distinction here - the variable is being used in
code by code, within that particular instance of the form, and what's
more the property value assignment will only be current for the duration
of that instance of the form. But when you are working in the design
view of the form, it has no knowledge of any value that may have been
assigned to a VBA variable.

Man, now you've got my head hurting too... good night.

(By the way, which land down under are you at?)
 
S

Steve

Im living and working in the worlds best kept secret place ( Perth Western
Australia ) shhhhhhhh dont tell to many or they will all want to come here.
hmmmmm how many people read these nerdy files ( proud to be a nerd )
Oh well the secrets out now.
regards
Steve - From a land down under or a land on top if your in outa space
 

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