Solved

type Mismatch DCount value

Posted on 2014-02-18
6
563 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
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.

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

867 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

15 Experts available now in Live!

Get 1:1 Help Now