?
Solved

type Mismatch DCount value

Posted on 2014-02-18
6
Medium Priority
?
582 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 26

Expert Comment

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

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

Accepted Solution

by:
PatHartman earned 2000 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

777 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