Errors from the Expression Builder

S

SadGrue

I'm trying to create a form where users can input default values for certain
fields for all new records, since they will be creating lots of records with
similar data, but it will change too often to use a global default on the
underlying table. It seemed simple enough in principle: I have an unbound
control I stuck on the form (a text box), and I want to set the default value
of a bound control to the value of the unbound control.

The problem is that when I go to the "Default Value" line in the property
sheet for the bound control, I can't for the life of me figure out how to get
it to read the value in the unbound control. I'm trying to use the expession
builder and just selecting the name of my unbound control, which produces a
default vaule line of "=[nameofunboundcontrol]" (that's obviously not what
it's called, but you know what I mean). This seems to easy to be true... and
it is. I have spent hours fiddling with it and can't get any result in my
bound control field on new records except "#Name?" - well, that or just blank.

Any advice on how to write an expression that will succesfully read as a
default a value from elsewhere on the form would be immensely appreciated.
 
W

Wayne-I-M

I assume you want to type something into your Unbound Control and then have
this placed into some other controls ??

If this is the case then use the AfterUpdate of the Unbound Control

Private Sub NameOfUnboundControl_AfterUpdate()
Me.TextBox1 = Me.NameOfUnboundControl
Me.TextBox2 = Me.NameOfUnboundControl
Me.TextBox3 = Me.NameOfUnboundControl
Me.TextBox4 = Me.NameOfUnboundControl
Me.TextBox5 = Me.NameOfUnboundControl
End Sub

Hope this helps
 
S

SadGrue

I appreciate the prompt resonse, and I'll give that a shot for solving my
immediate problem (it may take a while, never written a line of VB code
before). But I think maybe I explained too much, because what I really want
to know is what causes the expression "=[Nameofcontrol]" to return a value of
"#Name?" (Note that in the second case I'm not using "Name" as a stand-in the
way I am in the first case, the box in my form really says #Name?)

I'm missing something either really basic in expression syntax (which I've
had no trouble with elsewhere), or there's something I don't know about how
the default value works for form controls.


Wayne-I-M said:
I assume you want to type something into your Unbound Control and then have
this placed into some other controls ??

If this is the case then use the AfterUpdate of the Unbound Control

Private Sub NameOfUnboundControl_AfterUpdate()
Me.TextBox1 = Me.NameOfUnboundControl
Me.TextBox2 = Me.NameOfUnboundControl
Me.TextBox3 = Me.NameOfUnboundControl
Me.TextBox4 = Me.NameOfUnboundControl
Me.TextBox5 = Me.NameOfUnboundControl
End Sub

Hope this helps

--
Wayne
Manchester, England.



SadGrue said:
I'm trying to create a form where users can input default values for certain
fields for all new records, since they will be creating lots of records with
similar data, but it will change too often to use a global default on the
underlying table. It seemed simple enough in principle: I have an unbound
control I stuck on the form (a text box), and I want to set the default value
of a bound control to the value of the unbound control.

The problem is that when I go to the "Default Value" line in the property
sheet for the bound control, I can't for the life of me figure out how to get
it to read the value in the unbound control. I'm trying to use the expession
builder and just selecting the name of my unbound control, which produces a
default vaule line of "=[nameofunboundcontrol]" (that's obviously not what
it's called, but you know what I mean). This seems to easy to be true... and
it is. I have spent hours fiddling with it and can't get any result in my
bound control field on new records except "#Name?" - well, that or just blank.

Any advice on how to write an expression that will succesfully read as a
default a value from elsewhere on the form would be immensely appreciated.
 
W

Wayne-I-M

I don't know - it "should" work

I can't see anything you have done wrong.

If you have 2 controls
TextBox1 and TextBox2

In TextBox2 (in the Data Column - Control Source row) you would put
=[TextBox1]

This means that whatever you put into TextBox1 will go into TextBox2

Are you "sure" you have put the name of the "control" NOT the name of the
field it is based on.

Have a look in your nameofunboundcontrol - look in the "Other" column then
in the Name row to find the name of the control.


--
Wayne
Manchester, England.



SadGrue said:
I appreciate the prompt resonse, and I'll give that a shot for solving my
immediate problem (it may take a while, never written a line of VB code
before). But I think maybe I explained too much, because what I really want
to know is what causes the expression "=[Nameofcontrol]" to return a value of
"#Name?" (Note that in the second case I'm not using "Name" as a stand-in the
way I am in the first case, the box in my form really says #Name?)

I'm missing something either really basic in expression syntax (which I've
had no trouble with elsewhere), or there's something I don't know about how
the default value works for form controls.


Wayne-I-M said:
I assume you want to type something into your Unbound Control and then have
this placed into some other controls ??

If this is the case then use the AfterUpdate of the Unbound Control

Private Sub NameOfUnboundControl_AfterUpdate()
Me.TextBox1 = Me.NameOfUnboundControl
Me.TextBox2 = Me.NameOfUnboundControl
Me.TextBox3 = Me.NameOfUnboundControl
Me.TextBox4 = Me.NameOfUnboundControl
Me.TextBox5 = Me.NameOfUnboundControl
End Sub

Hope this helps

--
Wayne
Manchester, England.



SadGrue said:
I'm trying to create a form where users can input default values for certain
fields for all new records, since they will be creating lots of records with
similar data, but it will change too often to use a global default on the
underlying table. It seemed simple enough in principle: I have an unbound
control I stuck on the form (a text box), and I want to set the default value
of a bound control to the value of the unbound control.

The problem is that when I go to the "Default Value" line in the property
sheet for the bound control, I can't for the life of me figure out how to get
it to read the value in the unbound control. I'm trying to use the expession
builder and just selecting the name of my unbound control, which produces a
default vaule line of "=[nameofunboundcontrol]" (that's obviously not what
it's called, but you know what I mean). This seems to easy to be true... and
it is. I have spent hours fiddling with it and can't get any result in my
bound control field on new records except "#Name?" - well, that or just blank.

Any advice on how to write an expression that will succesfully read as a
default a value from elsewhere on the form would be immensely appreciated.
 
S

SadGrue

I'm quite certain I'm using the right name - I've tried selecting it off the
expression builder as well as typing it by hand - I also tried
[NameofForm]![NameofControl] just for the heck of it, although my
understanding is that wouldn't be necessary since the form is obviously
active. I also tried renaming the control (renaming it from the property
sheet, not just changing the label).

The one thing I've been doing differently is that I've been using the
"default value" line in the property sheet, not the "control source". I
tried it your way and still got "#Name?", except that now it overwrote #Name?
in the field in question on the already existing records in the datasheet
view (I'm using a split form) - which I don't want even if it was working
correctly. I'm pretty sure the default value is what I want to use.

I'll try your code solution, since I can't figure this #Name? problem, but
it really bothers me that I can't resolve it. I've spent more time on it
than anything else in the DB, and it's kicking my [hindquarters].

Wayne-I-M said:
I don't know - it "should" work

I can't see anything you have done wrong.

If you have 2 controls
TextBox1 and TextBox2

In TextBox2 (in the Data Column - Control Source row) you would put
=[TextBox1]

This means that whatever you put into TextBox1 will go into TextBox2

Are you "sure" you have put the name of the "control" NOT the name of the
field it is based on.

Have a look in your nameofunboundcontrol - look in the "Other" column then
in the Name row to find the name of the control.


--
Wayne
Manchester, England.



SadGrue said:
I appreciate the prompt resonse, and I'll give that a shot for solving my
immediate problem (it may take a while, never written a line of VB code
before). But I think maybe I explained too much, because what I really want
to know is what causes the expression "=[Nameofcontrol]" to return a value of
"#Name?" (Note that in the second case I'm not using "Name" as a stand-in the
way I am in the first case, the box in my form really says #Name?)

I'm missing something either really basic in expression syntax (which I've
had no trouble with elsewhere), or there's something I don't know about how
the default value works for form controls.


Wayne-I-M said:
I assume you want to type something into your Unbound Control and then have
this placed into some other controls ??

If this is the case then use the AfterUpdate of the Unbound Control

Private Sub NameOfUnboundControl_AfterUpdate()
Me.TextBox1 = Me.NameOfUnboundControl
Me.TextBox2 = Me.NameOfUnboundControl
Me.TextBox3 = Me.NameOfUnboundControl
Me.TextBox4 = Me.NameOfUnboundControl
Me.TextBox5 = Me.NameOfUnboundControl
End Sub

Hope this helps

--
Wayne
Manchester, England.



:

I'm trying to create a form where users can input default values for certain
fields for all new records, since they will be creating lots of records with
similar data, but it will change too often to use a global default on the
underlying table. It seemed simple enough in principle: I have an unbound
control I stuck on the form (a text box), and I want to set the default value
of a bound control to the value of the unbound control.

The problem is that when I go to the "Default Value" line in the property
sheet for the bound control, I can't for the life of me figure out how to get
it to read the value in the unbound control. I'm trying to use the expession
builder and just selecting the name of my unbound control, which produces a
default vaule line of "=[nameofunboundcontrol]" (that's obviously not what
it's called, but you know what I mean). This seems to easy to be true... and
it is. I have spent hours fiddling with it and can't get any result in my
bound control field on new records except "#Name?" - well, that or just blank.

Any advice on how to write an expression that will succesfully read as a
default a value from elsewhere on the form would be immensely appreciated.
 
W

Wayne-I-M

Open your form in design view.

Delete all the =[SomeName] that you have added in the default values and
also any that you may have added into the control source

NOTE
If you want to store the value into a field you must have the control source
as the field name in the table (select it from the drop down in the control
source row)

Right click the Unboundfield
Open the property box
In the Event column slect the AfterUpdate row
Select the build option (...)
Select Code
You will this

Private Sub NameOfUnboundControl_AfterUpdate()

End Sub

Of course the name will be different (NameOfUnboundControl)
Add this in between the 2 lines of code

Me.TextBox1 = Me.NameOfUnboundControl
Me.TextBox2 = Me.NameOfUnboundControl
Me.TextBox3 = Me.NameOfUnboundControl
Me.TextBox4 = Me.NameOfUnboundControl
Me.TextBox5 = Me.NameOfUnboundControl

Change the name of the NameOfUnboundControl to what it really is
Change each TextBox1 2 3 4 5 to what they really are (add more if you want
or delete a few.

Tip - You can check the Name of the unbound form by
Me.TextBoxName (with the real name of the control)
then type Me.
The unbound box should appear on the list



--
Wayne
Manchester, England.



SadGrue said:
I'm quite certain I'm using the right name - I've tried selecting it off the
expression builder as well as typing it by hand - I also tried
[NameofForm]![NameofControl] just for the heck of it, although my
understanding is that wouldn't be necessary since the form is obviously
active. I also tried renaming the control (renaming it from the property
sheet, not just changing the label).

The one thing I've been doing differently is that I've been using the
"default value" line in the property sheet, not the "control source". I
tried it your way and still got "#Name?", except that now it overwrote #Name?
in the field in question on the already existing records in the datasheet
view (I'm using a split form) - which I don't want even if it was working
correctly. I'm pretty sure the default value is what I want to use.

I'll try your code solution, since I can't figure this #Name? problem, but
it really bothers me that I can't resolve it. I've spent more time on it
than anything else in the DB, and it's kicking my [hindquarters].

Wayne-I-M said:
I don't know - it "should" work

I can't see anything you have done wrong.

If you have 2 controls
TextBox1 and TextBox2

In TextBox2 (in the Data Column - Control Source row) you would put
=[TextBox1]

This means that whatever you put into TextBox1 will go into TextBox2

Are you "sure" you have put the name of the "control" NOT the name of the
field it is based on.

Have a look in your nameofunboundcontrol - look in the "Other" column then
in the Name row to find the name of the control.


--
Wayne
Manchester, England.



SadGrue said:
I appreciate the prompt resonse, and I'll give that a shot for solving my
immediate problem (it may take a while, never written a line of VB code
before). But I think maybe I explained too much, because what I really want
to know is what causes the expression "=[Nameofcontrol]" to return a value of
"#Name?" (Note that in the second case I'm not using "Name" as a stand-in the
way I am in the first case, the box in my form really says #Name?)

I'm missing something either really basic in expression syntax (which I've
had no trouble with elsewhere), or there's something I don't know about how
the default value works for form controls.


:

I assume you want to type something into your Unbound Control and then have
this placed into some other controls ??

If this is the case then use the AfterUpdate of the Unbound Control

Private Sub NameOfUnboundControl_AfterUpdate()
Me.TextBox1 = Me.NameOfUnboundControl
Me.TextBox2 = Me.NameOfUnboundControl
Me.TextBox3 = Me.NameOfUnboundControl
Me.TextBox4 = Me.NameOfUnboundControl
Me.TextBox5 = Me.NameOfUnboundControl
End Sub

Hope this helps

--
Wayne
Manchester, England.



:

I'm trying to create a form where users can input default values for certain
fields for all new records, since they will be creating lots of records with
similar data, but it will change too often to use a global default on the
underlying table. It seemed simple enough in principle: I have an unbound
control I stuck on the form (a text box), and I want to set the default value
of a bound control to the value of the unbound control.

The problem is that when I go to the "Default Value" line in the property
sheet for the bound control, I can't for the life of me figure out how to get
it to read the value in the unbound control. I'm trying to use the expession
builder and just selecting the name of my unbound control, which produces a
default vaule line of "=[nameofunboundcontrol]" (that's obviously not what
it's called, but you know what I mean). This seems to easy to be true... and
it is. I have spent hours fiddling with it and can't get any result in my
bound control field on new records except "#Name?" - well, that or just blank.

Any advice on how to write an expression that will succesfully read as a
default a value from elsewhere on the form would be immensely appreciated.
 

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