recordcount null

  • Thread starter Thread starter rudwan
  • Start date Start date
R

rudwan

suppose i have button on a form , this button has code to
count records of filterd query ,
i but like this
dim m as integer
m=dcount("employeeID","Employee","[EmployeeID]="&ME.EMPID)
if isnull(m) then
'do nothing
else
msgbox m
end if

this works perfectly , but when there is no record , it
should be do nothing , but actually it stopped teh code
sending message that " invalid use of null "
 
DCount should return a 0 when there are no records meeting the criteria.
Try your code as follows:

if m = 0 then
'do nothing
else
msgbox m
end if

hth,
 
To be sure, I would need a bit mor info, but i believe
that since m is an integer you should search for 0 (zero)
instead of Null.

Try:

If m = 0 then
'do nothing
Else
Your Message
End if

To know if worked, substitute a Msgbox with "There are no
records that match this search" for your 'do nothing.
 
While I agree with the previous two responses, it is not clear from your msg
where the problem is.

If for example the Me.EmpId is null, then you'll fail on the DCount
statement and not later.

In summary, then
(a) since DCount returns 0 and not null, m can correctly be defined as
Integer, and so an IsNull test is inappropriate.
(b) if there is a chance that Me.EmpId is null, you should protect the
DCount statement.

Your code could read:
dim m as Integer
if IsNull(Me.EmpId) Then
m = 0
else
m=DCount("employeeID","Employee","[EmployeeID]="&ME.EMPID)
endif
if m = 0 then
'do nothing
else
msgbox m
end if

CD
 
i changed formula to be as your advice :
if m=0 then
but it gives the same error



-----Original Message-----
To be sure, I would need a bit mor info, but i believe
that since m is an integer you should search for 0 (zero)
instead of Null.

Try:

If m = 0 then
'do nothing
Else
Your Message
End if

To know if worked, substitute a Msgbox with "There are no
records that match this search" for your 'do nothing.


-----Original Message-----
suppose i have button on a form , this button has code to
count records of filterd query ,
i but like this
dim m as integer
m=dcount("employeeID","Employee","[EmployeeID] ="&ME.EMPID)
if isnull(m) then
'do nothing
else
msgbox m
end if

this works perfectly , but when there is no record , it
should be do nothing , but actually it stopped teh code
sending message that " invalid use of null "
.
.
 
i forget to change function from dlookup to dcount
it gives the result .
ok
-----Original Message-----
To be sure, I would need a bit mor info, but i believe
that since m is an integer you should search for 0 (zero)
instead of Null.

Try:

If m = 0 then
'do nothing
Else
Your Message
End if

To know if worked, substitute a Msgbox with "There are no
records that match this search" for your 'do nothing.


-----Original Message-----
suppose i have button on a form , this button has code to
count records of filterd query ,
i but like this
dim m as integer
m=dcount("employeeID","Employee","[EmployeeID] ="&ME.EMPID)
if isnull(m) then
'do nothing
else
msgbox m
end if

this works perfectly , but when there is no record , it
should be do nothing , but actually it stopped teh code
sending message that " invalid use of null "
.
.
 
hi chadlon ;
m.empid cannot be null , i mean the code will take value
of m.empid and search in another recordset to know whether
this employee has any record their ( old ) , or not ( new
employee)
i remember your smart idea , what do you advice now ?
-----Original Message-----
While I agree with the previous two responses, it is not clear from your msg
where the problem is.

If for example the Me.EmpId is null, then you'll fail on the DCount
statement and not later.

In summary, then
(a) since DCount returns 0 and not null, m can correctly be defined as
Integer, and so an IsNull test is inappropriate.
(b) if there is a chance that Me.EmpId is null, you should protect the
DCount statement.

Your code could read:
dim m as Integer
if IsNull(Me.EmpId) Then
m = 0
else
m=DCount("employeeID","Employee","[EmployeeID] ="&ME.EMPID)
endif
if m = 0 then
'do nothing
else
msgbox m
end if

CD


suppose i have button on a form , this button has code to
count records of filterd query ,
i but like this
dim m as integer
m=dcount("employeeID","Employee","[EmployeeID] ="&ME.EMPID)
if isnull(m) then
'do nothing
else
msgbox m
end if

this works perfectly , but when there is no record , it
should be do nothing , but actually it stopped teh code
sending message that " invalid use of null "


.
 
Hello again,
You're clearly making a lot of progress in the month since last we spoke.

Your comment to Wayne ... do I gather the problem is now solved?

I confess I wasn't entirely happy with my reply to you, but I was also
uncomfortable just to leave the only suggestion as "m = 0" instead of
IsNull, since I could not see how that delivers the error message you
report.
But then neither would my explanation - or any other interpretation of the
code as posted.

One way to get the reported error is
MsgBox Null
but with m defined as Integer, that can't be the route you've found.

If you are now saying that the function used was DLookup and not DCount,
then the error you are getting is if/when the DLookup returns Null and the
assignment into m - an integer variable - fails.

If you are simply trying to determine if a specific employee code exists,
you could manage without a variable:
Function EmployeeId_on_file(empId as Long) As Boolean
EmployeeId_on_file = Not
IsNull(DLookup("employeeID","Employee","[EmployeeID]="&CStr(empId)))
End Function

CD


rudwan said:
hi chadlon ;
m.empid cannot be null , i mean the code will take value
of m.empid and search in another recordset to know whether
this employee has any record their ( old ) , or not ( new
employee)
i remember your smart idea , what do you advice now ?
-----Original Message-----
While I agree with the previous two responses, it is not clear from your msg
where the problem is.

If for example the Me.EmpId is null, then you'll fail on the DCount
statement and not later.

In summary, then
(a) since DCount returns 0 and not null, m can correctly be defined as
Integer, and so an IsNull test is inappropriate.
(b) if there is a chance that Me.EmpId is null, you should protect the
DCount statement.

Your code could read:
dim m as Integer
if IsNull(Me.EmpId) Then
m = 0
else
m=DCount("employeeID","Employee","[EmployeeID] ="&ME.EMPID)
endif
if m = 0 then
'do nothing
else
msgbox m
end if

CD


suppose i have button on a form , this button has code to
count records of filterd query ,
i but like this
dim m as integer
m=dcount("employeeID","Employee","[EmployeeID] ="&ME.EMPID)
if isnull(m) then
'do nothing
else
msgbox m
end if

this works perfectly , but when there is no record , it
should be do nothing , but actually it stopped teh code
sending message that " invalid use of null "


.
 
You still my prefferable expert , usually i get a good
idea from you , the problem solved before , by changing
m=0 instead isnoull( m ) ,
but i will try your advice to be more developed

-----Original Message-----
Hello again,
You're clearly making a lot of progress in the month since last we spoke.

Your comment to Wayne ... do I gather the problem is now solved?

I confess I wasn't entirely happy with my reply to you, but I was also
uncomfortable just to leave the only suggestion as "m = 0" instead of
IsNull, since I could not see how that delivers the error message you
report.
But then neither would my explanation - or any other interpretation of the
code as posted.

One way to get the reported error is
MsgBox Null
but with m defined as Integer, that can't be the route you've found.

If you are now saying that the function used was DLookup and not DCount,
then the error you are getting is if/when the DLookup returns Null and the
assignment into m - an integer variable - fails.

If you are simply trying to determine if a specific employee code exists,
you could manage without a variable:
Function EmployeeId_on_file(empId as Long) As Boolean
EmployeeId_on_file = Not
IsNull(DLookup("employeeID","Employee","[EmployeeID] ="&CStr(empId)))
End Function

CD


hi chadlon ;
m.empid cannot be null , i mean the code will take value
of m.empid and search in another recordset to know whether
this employee has any record their ( old ) , or not ( new
employee)
i remember your smart idea , what do you advice now ?
-----Original Message-----
While I agree with the previous two responses, it is
not
clear from your msg
where the problem is.

If for example the Me.EmpId is null, then you'll fail
on
the DCount
statement and not later.

In summary, then
(a) since DCount returns 0 and not null, m can
correctly
be defined as
Integer, and so an IsNull test is inappropriate.
(b) if there is a chance that Me.EmpId is null, you should protect the
DCount statement.

Your code could read:
dim m as Integer
if IsNull(Me.EmpId) Then
m = 0
else
m=DCount("employeeID","Employee","[EmployeeID] ="&ME.EMPID)
endif
if m = 0 then
'do nothing
else
msgbox m
end if

CD


suppose i have button on a form , this button has
code
to
count records of filterd query ,
i but like this
dim m as integer
m=dcount("employeeID","Employee","[EmployeeID] ="&ME.EMPID)
if isnull(m) then
'do nothing
else
msgbox m
end if

this works perfectly , but when there is no record , it
should be do nothing , but actually it stopped teh code
sending message that " invalid use of null "


.


.
 
Back
Top