Solved

type Mismatch DCount value

Posted on 2014-02-18
6
558 Views
Last Modified: 2014-02-20
I am getting type mismatch when I need to get a record count based on the following dCount. (see '>>>>>)  I attempting do determine if records exists in the TblsummaryQuartersFrozen, where the quarter = (i) and if true then proceed to process queries..

I have tried changing the variable type, single, string, variant, etc - no luck - What am I missing:

   
Dim ExtractDate As Date
Dim curDB As DAO.Database
Dim strSQL As String, strSQL1 As String
Dim nCt As Variant
Dim rs As DAO.Recordset, rs1 As DAO.Recordset
Dim i As Integer

 strSQL = "Select Year, FreezeQ1, FreezeQ2, FreezeQ3, FreezeQ4 from tblcurrent"

    Set rs = curDB.OpenRecordset(strSQL)
   For i = 1 To 4
">>>>>>        nCt = Nz(DCount("Quarter", "tblSummaryQuartersFrozen", "Quarter = " & i And "Year =" & Year(Date)))
           If rs.Fields("CountOfQuarter") > 0 Then
           
           ' If nCt = 0 Then
                GoTo cont:
            ElseIf rs.Fields("FreezeQ" & (i)) = -1 Then
                curDB.Execute ("DELETE *" & _
                               " FROM tblSummary" & _
                               " WHERE Quarter = " & i And "Year =" & Year(Date))
                curDB.Execute ("INSERT INTO tblSummary" & _
                               "Select *" & _
                               " FROM tblSummaryQuartersFrozen" & _
                               " WHERE Quarter = " & i And "Year =" & Year(Date))
                rs.MoveNext
            End If
     Next i
cont:

Open in new window

0
Comment
Question by:Karen Schaefer
6 Comments
 
LVL 26

Expert Comment

by:jerryb30
ID: 39869087
nCt = Nz(DCount("Quarter", "tblSummaryQuartersFrozen", "Quarter = " & i & " And Year =" & Year(Date)))
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39869891
As DCount returns 0 as a minimum, it should read:

Dim nCt As Long

nCt = DCount("*", "tblSummaryQuartersFrozen", "Quarter = " & i & " And Year = " & Year(Date) & "")

/gustav
0
 

Author Comment

by:Karen Schaefer
ID: 39870779
I have tried both suggestions and I am still getting the same error message.

Dim curDB As DAO.Database
Dim strSQL As String, strSQL1 As String
Dim nCt As Long
Dim rs As DAO.Recordset, rs1 As DAO.Recordset
Dim i As Integer

    strSQL = "Select Year, FreezeQ1, FreezeQ2, FreezeQ3, FreezeQ4 from tblcurrent"

    Set rs = curDB.OpenRecordset(strSQL)
'    strSQL1 = "SELECT Count(Quarter) AS CountOfQuarter, Quarter" & _
'                " FROM tblSummaryQuartersFrozen" & _
'                " WHERE (((Year) = Year(Date)))" & _
'                " GROUP BY Quarter" & _
'                " HAVING (((Quarter)='1')) OR (((Quarter)='2')) OR (((Quarter)='3')) OR (((Quarter)='4'))"
'     Set rs1 = curDB.OpenRecordset(strSQL1)
   For i = 1 To 4
  ' Dim nCt As Long
nCt = DCount("*", "tblSummaryQuartersFrozen", "Quarter = " & i & " And Year = " & Year(Date) & "")

    nCt = Nz(DCount("Quarter", "tblSummaryQuartersFrozen", "Quarter = " & i & " And Year =" & Year(Date)))
   '     nCt = Nz(DCount("*", "tblSummaryQuartersFrozen", "Quarter = " & i And "Year =" & Year(Date)))

Open in new window

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:Karen Schaefer
ID: 39870847
still looking for help.
0
 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
ID: 39874612
You have used reserved names as column names and so you need to be diligent about enclosing all the mis-named columns in square brackets.  If you don't, you run the risk of the column name being interpreted as if it were the function.

In the future, try to avoid using reserved words as column names.  Access will warn you in some cases but perhaps not all.  The best way to be sure you are not running into any name that is already taken is to use compound words.  Such as SaleDate, ForecastYear, CompanyName.  These are more descriptive and you can be pretty sure that Access, Jet/ACE, and VBA haven't already squatted on them.
0
 

Author Closing Comment

by:Karen Schaefer
ID: 39875357
thanks for the input
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now