Dreaded #Name?

G

Guest

In Form2, I have a save button which will update a listbox and a textbox in
Form1. My code in the Form2 save button looks like this:

Forms!Form1!listbox1.Requery
Forms!Form1!txtTotal.ControlSource =
DSum("[table1]![field1]","[table1]","[lngPNo]=Forms!Form1!lngPNo")

When I click on the Save button, I the listbox in Form1 works properly but
the field in Form1 shows #Name?. When I right-click on it and look at the
properties and controlsource, the number is there but it's just not
displaying. Any ideas? Thanks.
ck
 
N

Nikos Yannacopoulos

Bad syntax in DSum. Also, do you really need to change the control's
controlsource property? Or are you just trying to update its value,
which makes more sense? To do the latter:

Forms!Form1!txtTotal = DSum("[field1]","table1","[lngPNo]= " &
Forms!Form1!lngPNo)
(all in one line, watch out for NG wrapping!)

The above assumes lngPNo is numeric. In case it's text:

Forms!Form1!txtTotal = DSum("[field1]","table1","[lngPNo]= '" &
Forms!Form1!lngPNo & "'")
(again, all in one line).

HTH,
Nikos
 
G

Guest

Thanks, Nikos for the tip. txtTotal is an unbound field which I wanted to
show the total. I originally had the DSum in the controlsource property but I
keep getting a "Invalid use of null" error so I assign the DSum expression to
the controlsource property from Form2 instead.

If I use what you have suggested (without the .controlsource property), I
get an error "You can't assign a value to this object."

If I use with the .controlsource property, I still get the #Name? displayed
in the txtTotal control. lngPNo is numeric while txtTotal is an unbound
control. Any ideas? Thanks.
ck

Nikos Yannacopoulos said:
Bad syntax in DSum. Also, do you really need to change the control's
controlsource property? Or are you just trying to update its value,
which makes more sense? To do the latter:

Forms!Form1!txtTotal = DSum("[field1]","table1","[lngPNo]= " &
Forms!Form1!lngPNo)
(all in one line, watch out for NG wrapping!)

The above assumes lngPNo is numeric. In case it's text:

Forms!Form1!txtTotal = DSum("[field1]","table1","[lngPNo]= '" &
Forms!Form1!lngPNo & "'")
(again, all in one line).

HTH,
Nikos

In Form2, I have a save button which will update a listbox and a textbox in
Form1. My code in the Form2 save button looks like this:

Forms!Form1!listbox1.Requery
Forms!Form1!txtTotal.ControlSource =
DSum("[table1]![field1]","[table1]","[lngPNo]=Forms!Form1!lngPNo")

When I click on the Save button, I the listbox in Form1 works properly but
the field in Form1 shows #Name?. When I right-click on it and look at the
properties and controlsource, the number is there but it's just not
displaying. Any ideas? Thanks.
ck
 
G

Guest

It's working now...phew. My mistake..I forgot to clear the controlsource
value that which was assigned earlier. Thanks again, Nikos.
ck

Nikos Yannacopoulos said:
Bad syntax in DSum. Also, do you really need to change the control's
controlsource property? Or are you just trying to update its value,
which makes more sense? To do the latter:

Forms!Form1!txtTotal = DSum("[field1]","table1","[lngPNo]= " &
Forms!Form1!lngPNo)
(all in one line, watch out for NG wrapping!)

The above assumes lngPNo is numeric. In case it's text:

Forms!Form1!txtTotal = DSum("[field1]","table1","[lngPNo]= '" &
Forms!Form1!lngPNo & "'")
(again, all in one line).

HTH,
Nikos

In Form2, I have a save button which will update a listbox and a textbox in
Form1. My code in the Form2 save button looks like this:

Forms!Form1!listbox1.Requery
Forms!Form1!txtTotal.ControlSource =
DSum("[table1]![field1]","[table1]","[lngPNo]=Forms!Form1!lngPNo")

When I click on the Save button, I the listbox in Form1 works properly but
the field in Form1 shows #Name?. When I right-click on it and look at the
properties and controlsource, the number is there but it's just not
displaying. Any ideas? Thanks.
ck
 
N

Nikos Yannacopoulos

I underdstand the form, control, table, field names in your post are not
the actual ones... can you please post the exact expression you are
using? Any chance you are trying to do this while the form (form1) is in
design view?

The reason why you get the error when attempting to change the
controlsource proprty is the DLookup expression syntax (the quotes, in
particular) would be different in the form design context than in code.

Nikos
Thanks, Nikos for the tip. txtTotal is an unbound field which I wanted to
show the total. I originally had the DSum in the controlsource property but I
keep getting a "Invalid use of null" error so I assign the DSum expression to
the controlsource property from Form2 instead.

If I use what you have suggested (without the .controlsource property), I
get an error "You can't assign a value to this object."

If I use with the .controlsource property, I still get the #Name? displayed
in the txtTotal control. lngPNo is numeric while txtTotal is an unbound
control. Any ideas? Thanks.
ck

:

Bad syntax in DSum. Also, do you really need to change the control's
controlsource property? Or are you just trying to update its value,
which makes more sense? To do the latter:

Forms!Form1!txtTotal = DSum("[field1]","table1","[lngPNo]= " &
Forms!Form1!lngPNo)
(all in one line, watch out for NG wrapping!)

The above assumes lngPNo is numeric. In case it's text:

Forms!Form1!txtTotal = DSum("[field1]","table1","[lngPNo]= '" &
Forms!Form1!lngPNo & "'")
(again, all in one line).

HTH,
Nikos

In Form2, I have a save button which will update a listbox and a textbox in
Form1. My code in the Form2 save button looks like this:

Forms!Form1!listbox1.Requery
Forms!Form1!txtTotal.ControlSource =
DSum("[table1]![field1]","[table1]","[lngPNo]=Forms!Form1!lngPNo")

When I click on the Save button, I the listbox in Form1 works properly but
the field in Form1 shows #Name?. When I right-click on it and look at the
properties and controlsource, the number is there but it's just not
displaying. Any ideas? Thanks.
ck
 
N

Nikos Yannacopoulos

Good!
It's working now...phew. My mistake..I forgot to clear the controlsource
value that which was assigned earlier. Thanks again, Nikos.
ck

:

Bad syntax in DSum. Also, do you really need to change the control's
controlsource property? Or are you just trying to update its value,
which makes more sense? To do the latter:

Forms!Form1!txtTotal = DSum("[field1]","table1","[lngPNo]= " &
Forms!Form1!lngPNo)
(all in one line, watch out for NG wrapping!)

The above assumes lngPNo is numeric. In case it's text:

Forms!Form1!txtTotal = DSum("[field1]","table1","[lngPNo]= '" &
Forms!Form1!lngPNo & "'")
(again, all in one line).

HTH,
Nikos

In Form2, I have a save button which will update a listbox and a textbox in
Form1. My code in the Form2 save button looks like this:

Forms!Form1!listbox1.Requery
Forms!Form1!txtTotal.ControlSource =
DSum("[table1]![field1]","[table1]","[lngPNo]=Forms!Form1!lngPNo")

When I click on the Save button, I the listbox in Form1 works properly but
the field in Form1 shows #Name?. When I right-click on it and look at the
properties and controlsource, the number is there but it's just not
displaying. Any ideas? Thanks.
ck
 

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