+ Reply to Thread
Results 1 to 5 of 5

Dcount Type Mismatch error

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Dcount Type Mismatch error

    Hi,

    I am trying to build a macro which will run when a form opens. I am trying to create a macro which first ask for a number to be entered. Then take that number a count however records in a table with that member number are listed with a yes/no field called Disc check as yes.

    However my code keeps getting a Type Mismatch error on the line highlighted below:
    Private Sub Form_Load()
    Dim Claims As String
    Dim Num As String
    
    Num = InputBox("Enter a Number", "Number")
    
    If Num = "" Then
        MsgBox "There was no number entered please try again"
        DoCmd.OpenForm "frmMenu", acNormal
        Exit Sub
    End If
    
    Me.Text9.Value = Num
    
    Claims = Application.DCount("Number] & [Disc]", "Files", "[Number] = " & Num And "[Disc] = -1")
    
    If Claims = "0" Then
        Me.Text6.Value = "This number does not have a disc"
    End If
    
    End Sub
    Can any help with this error? As I can not get it to work.

    Thank you,

    Jeskit

  2. #2
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Dcount Type Mismatch error

    Hi Jeskit,

    I think.. any D-Formula doesn't work with ARRAY.. it needs a range.. where we need to specify Conditions..

    If it possible to store the DATA & Condition is a separate area in the gridsheet.. and in macro provide the complete range like "M1:O3".. hope it will work..

    Please upload sample file with expected output..

    Regards,
    Deb

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Dcount Type Mismatch error

    Is this an access question or excel?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Forum Contributor
    Join Date
    05-05-2009
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010 and 365
    Posts
    113

    Re: Dcount Type Mismatch error

    Quote Originally Posted by jeskit View Post
    Hi,

    I am trying to build a macro which will run when a form opens. I am trying to create a macro which first ask for a number to be entered. Then take that number a count however records in a table with that member number are listed with a yes/no field called Disc check as yes.

    However my code keeps getting a Type Mismatch error on the line highlighted below:
    Private Sub Form_Load()
    Dim Claims As String
    Dim Num As String
    
    Num = InputBox("Enter a Number", "Number")
    
    If Num = "" Then
        MsgBox "There was no number entered please try again"
        DoCmd.OpenForm "frmMenu", acNormal
        Exit Sub
    End If
    
    Me.Text9.Value = Num
    
    Claims = Application.DCount("Number] & [Disc]", "Files", "[Number] = " & Num And "[Disc] = -1")
    
    If Claims = "0" Then
        Me.Text6.Value = "This number does not have a disc"
    End If
    
    End Sub
    Can any help with this error? As I can not get it to work.

    Thank you,

    Jeskit
    Access Question...


    I would guess the problem is with


    "Number] & [Disc]"
    You are missing the bracket before number but I also don't know that you need or want two fields there. Pick a field that you know will have a value in it. Any value should do.

    Maybe

    Claims = Application.DCount("[Number]", "Files", "[Number] = " & Num And "[Disc] = -1")


    Also see:

    http://office.microsoft.com/en-us/ac...001228817.aspx

  5. #5
    Forum Contributor
    Join Date
    05-05-2009
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010 and 365
    Posts
    113

    Re: Dcount Type Mismatch error

    Actually I don't think that's quite right. The And needs to be part of the string too


    Claims = Application.DCount("[Number]", "Files", "[Number] = " & Num & "And [Disc] = -1")
    If that doesn't work then try

    Claims = Application.DCount("[Number]", "Files", "[Number] = '" & num & "' And [Disc] = '-1'")
    You need the single quotes for text values not sure if you need them for numbers.
    Last edited by Cyclops; 06-14-2013 at 04:30 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1