John Sheehy
asked on
Count of records with IT in their title
Below is the SQL I am using to have my app display only the count of records that have IT in their title and have earned the IDW qualification.
strSQL = "SELECT Count(tblMember.COMPASSID) AS MemberCount " & _
"FROM tblMember " & _
"WHERE Left$(RankRate, 2 ) = 'IT' and (tblMember.PrimaryWarfareD esignator) Like 'IDW' and ((tblMember.DelStatus)=Fal se)and((tb lMember.Ci vilian)=Fa lse);"
Only I keep getting a syntax error on the statement.
Any thoughts
strSQL = "SELECT Count(tblMember.COMPASSID)
"FROM tblMember " & _
"WHERE Left$(RankRate, 2 ) = 'IT' and (tblMember.PrimaryWarfareD
Only I keep getting a syntax error on the statement.
Any thoughts
ASKER
I get a runtime error 3061
Too few parameters. Expected 1
Here is the whole code
Function CoreIDW() As Integer
'------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
' Return the number of members in the tblMember table that are ITs and have qualified IDW
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
Dim dbCurrent As Database
Dim rsMembers As Recordset
Dim strSQL As String
' Form the SQL string
strSQL = "SELECT Count(tblMember.COMPASSID) AS MemberCount " & _
"FROM tblMember " & _
"WHERE Left(RankRate, 2) = 'IT' AND PrimaryWarfareDesignator Like '*IDW*' AND DelStatus=False AND Civilian=False"
Set dbCurrent = CurrentDb
' Populate a recordset using the SQL string
Set rsMembers = dbCurrent.OpenRecordset(st rSQL)
If (IsNull(rsMembers.RecordCo unt) = True) Or (rsMembers.RecordCount = 0) Then
' No attendance records were returned for the Member
CoreIDW = 0
Else
' Did the Member attend any meetings?
rsMembers.MoveFirst
CoreIDW = rsMembers.Fields(0)
End If
End Function
Too few parameters. Expected 1
Here is the whole code
Function CoreIDW() As Integer
'-------------------------
' Return the number of members in the tblMember table that are ITs and have qualified IDW
--------------------------
Dim dbCurrent As Database
Dim rsMembers As Recordset
Dim strSQL As String
' Form the SQL string
strSQL = "SELECT Count(tblMember.COMPASSID)
"FROM tblMember " & _
"WHERE Left(RankRate, 2) = 'IT' AND PrimaryWarfareDesignator Like '*IDW*' AND DelStatus=False AND Civilian=False"
Set dbCurrent = CurrentDb
' Populate a recordset using the SQL string
Set rsMembers = dbCurrent.OpenRecordset(st
If (IsNull(rsMembers.RecordCo
' No attendance records were returned for the Member
CoreIDW = 0
Else
' Did the Member attend any meetings?
rsMembers.MoveFirst
CoreIDW = rsMembers.Fields(0)
End If
End Function
why don't you try to get what is inside strSQL using msgbox syntax
msgbox strSQL
use the above line for debugging purpose. This line should be introduced after
DelStatus=False AND Civilian=False"
i.e.
Function CoreIDW() As Integer
'------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
' Return the number of members in the tblMember table that are ITs and have qualified IDW
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
Dim dbCurrent As Database
Dim rsMembers As Recordset
Dim strSQL As String
' Form the SQL string
strSQL = "SELECT Count(tblMember.COMPASSID) AS MemberCount " & _
"FROM tblMember " & _
"WHERE Left(RankRate, 2) = 'IT' AND PrimaryWarfareDesignator Like '*IDW*' AND DelStatus=False AND Civilian=False"
msgbox strSQL
Set dbCurrent = CurrentDb
' Populate a recordset using the SQL string
Set rsMembers = dbCurrent.OpenRecordset(st rSQL)
If (IsNull(rsMembers.RecordCo unt) = True) Or (rsMembers.RecordCount = 0) Then
' No attendance records were returned for the Member
CoreIDW = 0
Else
' Did the Member attend any meetings?
rsMembers.MoveFirst
CoreIDW = rsMembers.Fields(0)
End If
End Function
============
Now after seeing the content of strSQL, you can correct the error easily by you.
msgbox strSQL
use the above line for debugging purpose. This line should be introduced after
DelStatus=False AND Civilian=False"
i.e.
Function CoreIDW() As Integer
'-------------------------
' Return the number of members in the tblMember table that are ITs and have qualified IDW
--------------------------
Dim dbCurrent As Database
Dim rsMembers As Recordset
Dim strSQL As String
' Form the SQL string
strSQL = "SELECT Count(tblMember.COMPASSID)
"FROM tblMember " & _
"WHERE Left(RankRate, 2) = 'IT' AND PrimaryWarfareDesignator Like '*IDW*' AND DelStatus=False AND Civilian=False"
msgbox strSQL
Set dbCurrent = CurrentDb
' Populate a recordset using the SQL string
Set rsMembers = dbCurrent.OpenRecordset(st
If (IsNull(rsMembers.RecordCo
' No attendance records were returned for the Member
CoreIDW = 0
Else
' Did the Member attend any meetings?
rsMembers.MoveFirst
CoreIDW = rsMembers.Fields(0)
End If
End Function
============
Now after seeing the content of strSQL, you can correct the error easily by you.
Check the spelling of your field names.
ASKER
Here is what I ended up using, but you were right there was a mis-spelling.
strSQL = "SELECT Count(tblMember.CompassID) AS MemberCount " & _
"FROM tblMember " & _
"WHERE ((tblMember.DelStatus)=Fal se)and((tb lMember.Ci vilian)=Fa lse) " & _
"HAVING ((tblMember.[Rank/Rate]) Like 'IT*') AND ((tblMember.PrimaryWarfare Designator ) Like 'IDW');"
Thanks
J
strSQL = "SELECT Count(tblMember.CompassID)
"FROM tblMember " & _
"WHERE ((tblMember.DelStatus)=Fal
"HAVING ((tblMember.[Rank/Rate]) Like 'IT*') AND ((tblMember.PrimaryWarfare
Thanks
J
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Now that works a heck of a lot faster. Thank you
Points well earned.
John
Points well earned.
John
ASKER
The answer was perfect and worked a heck of a lot faster then what I was expecting.
Open in new window