problem with DCount

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hi Everyone

I have a database consisting of a number of table. I also
have an input form which consists of main and sub forms.
One of the sub forms relates to one table. If I run the
sub form by itself the dcount statement below works:

inst = DCount("[CC Number]", "CC Table", "[CC Table].[CC
Number]= forms![CC Table]![CC Number]")

I realise it's not good practice to use the same names for
tables and forms but the structure of the statement is
correct and runs when run independently.

However, when it's run as part of the main data entry form
I get a very non descript error that I can're resolve.

I use the inst value to display an on screen message if
it's greater than 1.

Any ideas or suggestions welcome and thank you all in
advance. Peter
 
CAn you breakpoint this line and then check whether there is a value
for the following part in the immediate window :
?forms![CC Table]![CC Number]

If not then this is causing the problem.

- Raoul
 
Thanks Raoul
did the breakpoint and it returns error 2450, can't find
the form. Clearly the form is there as a sub form and
it's allowing me to enter data into and even manipulating
data for the same field (before doing the count, I run
some code to strip spaces from the data entered) and all
that works fine.

Any idea on how I can reference the form and field so it
works? As I say, if I run the sub form independently as a
single form the same code works just fine.

Thanks again for your help.
-----Original Message-----
CAn you breakpoint this line and then check whether there is a value
for the following part in the immediate window :
?forms![CC Table]![CC Number]

If not then this is causing the problem.

- Raoul

Peter said:
Hi Everyone

I have a database consisting of a number of table. I also
have an input form which consists of main and sub forms.
One of the sub forms relates to one table. If I run the
sub form by itself the dcount statement below works:

inst = DCount("[CC Number]", "CC Table", "[CC Table]. [CC
Number]= forms![CC Table]![CC Number]")

I realise it's not good practice to use the same names for
tables and forms but the structure of the statement is
correct and runs when run independently.

However, when it's run as part of the main data entry form
I get a very non descript error that I can're resolve.

I use the inst value to display an on screen message if
it's greater than 1.

Any ideas or suggestions welcome and thank you all in
advance. Peter
.
 
Yes you should reference it like this

Forms![ParentForm]![SubFormName]!Form![cc number]

- Raoul


Peter said:
Thanks Raoul
did the breakpoint and it returns error 2450, can't find
the form. Clearly the form is there as a sub form and
it's allowing me to enter data into and even manipulating
data for the same field (before doing the count, I run
some code to strip spaces from the data entered) and all
that works fine.

Any idea on how I can reference the form and field so it
works? As I say, if I run the sub form independently as a
single form the same code works just fine.

Thanks again for your help.
-----Original Message-----
CAn you breakpoint this line and then check whether there is a value
for the following part in the immediate window :
?forms![CC Table]![CC Number]

If not then this is causing the problem.

- Raoul

Peter said:
Hi Everyone

I have a database consisting of a number of table. I also
have an input form which consists of main and sub forms.
One of the sub forms relates to one table. If I run the
sub form by itself the dcount statement below works:

inst = DCount("[CC Number]", "CC Table", "[CC Table]. [CC
Number]= forms![CC Table]![CC Number]")

I realise it's not good practice to use the same names for
tables and forms but the structure of the statement is
correct and runs when run independently.

However, when it's run as part of the main data entry form
I get a very non descript error that I can're resolve.

I use the inst value to display an on screen message if
it's greater than 1.

Any ideas or suggestions welcome and thank you all in
advance. Peter
.
 
Back
Top