Results 1 to 7 of 7
  1. #1
    rcerda is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    18

    DCount Function not working

    I have a DCount function counts the value of receipts which may have the same number, but it does not work. It does not bring the number counted. So for instance if I am entering a new receipt, and i ask how many it found it brings a number > 0 which is wrong. So in my VBA code I ask if the number is greater than zero then do something else do something else. But since the value it passes is always incorrect the algorithm does not work.

    If DCount("[Guía_de_Recepción]", "Recepcionesausensi", "[Guía_de_Recepción] = " & [Guía_de_Recepción] & " ") > 0 Then

    The thing is, this same code works in another form perfect. So I do not know what is the issue.

    Thank you so much

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    no brackets for the form object,
    and if it is a text field, you need quotes around it:

    DCount("[Guía_de_Recepción]", "Recepcionesausensi", "[Guía_de_Recepción] = '" & me.Guía_de_Recepción & "'")

    if numeric ,its:
    DCount("[Guía_de_Recepción]", "Recepcionesausensi", "[Guía_de_Recepción] = " & me.Guía_de_Recepción )

    IS Guía_de_Recepción a form object?

  3. #3
    rcerda is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    18
    Yes it is a Form Object. I have tried both ways and it does not work.
    I am also trying with a DLookup which also works and it just nothing. I do not know what else to do at the moment to get it to work. I have put MsgBoxex to look at the values and it gives me the wrong values. ufff !!

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Can you upload a sample db so we could have a look?

  5. #5
    NTC is offline VIP
    Windows 10 Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    In the form where it does not work; double check & be sure you do not have, by coincidence or accident, any control with the same name as any of the parameters of the function

  6. #6
    rcerda is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    18
    Everything looks good so I really do not know. Now I am trying with DLookup which does basically the same. Here is the code:

    Option Compare Database
    Private Sub adnewrecord_Click()
    On Error Resume Next
    Dim Recepcionesausensi As Database
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim GuiaCheck As String
    CheckForEmpty
    If CheckForEmpty = False Then
    Response = MsgBox("Por favor ingrese todos los campos Aqui" & vbCrLf, vbOKOnly) = vbOK
    ClearControlFormatting

    Else

    GuiaCheck = DLookup("Recepcionesausensi.[Guia de Recepción]", "Recepcionesausensi", "Recepcionesausensi.[Guía de Recepción] = '" & Forms.frmsinglerecord![Guía de Recepción] & "'")
    If Not IsNull(GuiaCheck) Then


    Response = MsgBox("Ya existe un registro igual en su tabla. De igual forma quiere guardarlo ?:-" & vbCrLf, vbYesNo + vbExclamation)
    If Response = vbYes Then
    Set rst = CurrentDb.OpenRecordset("Recepcionesausensi")
    With rst
    rst.addNew
    rstRecepcionesausensi![Guía_de_Recepción] = Me.[Guía_de_Recepción].Value
    rstRecepcionesausensi![Status] = Me.Status.Value
    rstRecepcionesausensi![Fecha] = Me.Fecha.Value
    rstRecepcionesausensi![Fecha de Entrega] = Me.Fecha_de_Entrega.Value
    rstRecepcionesausensi![Cantidad] = Me.Cantidad.Value
    rstRecepcionesausensi![Marca] = Me.Marca.Value
    rstRecepcionesausensi![Nºde Serie] = Me.Nº_de_Serie.Value
    rstRecepcionesausensi![HP] = Me.HP.Value
    rstRecepcionesausensi![RPM] = Me.RPM.Value
    rstRecepcionesausensi![Volts] = Me.Volts.Value
    rstRecepcionesausensi![AMP] = Me.AMP.Value
    rstRecepcionesausensi![Hz] = Me.Hz.Value
    rstRecepcionesausensi![Parte] = Me.Parte.Value
    rstRecepcionesausensi![Detalles] = Me.Detalles.Value
    rstRecepcionesausensi.Update
    rstRecepcionesausensi.Close
    Set rstRecepcionesausensi = Nothing
    End With
    MsgBox ("Su registro fue incorporado con éxito " & vbOKOnly)
    DoCmd.GoToRecord , , acNewRec
    Else
    DoCmd.RunCommand acCmdUndo


    End If
    Else
    Set rst = CurrentDb.OpenRecordset("Recepcionesausensi")
    With rst
    rst.addNew
    rstRecepcionesausensi![Guía_de_Recepción] = Me.[Guía_de_Recepción].Value
    rstRecepcionesausensi![Status] = Me.Status.Value
    rstRecepcionesausensi![Fecha] = Me.Fecha.Value
    rstRecepcionesausensi![Fecha de Entrega] = Me.Fecha_de_Entrega.Value
    rstRecepcionesausensi![Cantidad] = Me.Cantidad.Value
    rstRecepcionesausensi![Marca] = Me.Marca.Value
    rstRecepcionesausensi![Nºde Serie] = Me.Nº_de_Serie.Value
    rstRecepcionesausensi![HP] = Me.HP.Value
    rstRecepcionesausensi![RPM] = Me.RPM.Value
    rstRecepcionesausensi![Volts] = Me.Volts.Value
    rstRecepcionesausensi![AMP] = Me.AMP.Value
    rstRecepcionesausensi![Hz] = Me.Hz.Value
    rstRecepcionesausensi![Parte] = Me.Parte.Value
    rstRecepcionesausensi![Detalles] = Me.Detalles.Value
    rstRecepcionesausensi.Update
    rstRecepcionesausensi.Close
    Set rstRecepcionesausensi = Nothing
    End With
    MsgBox ("Su registro fue incorporado con éxito" & vbOKOnly)
    DoCmd.GoToRecord , , acNewRec
    End If
    End If
    End Sub

    Thank you

  7. #7
    rcerda is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    18
    Unfortunatelly DLookup does not work either.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dcount Function
    By felixkiprono402@gmail.com in forum Access
    Replies: 10
    Last Post: 05-23-2017, 09:26 AM
  2. Count and Dcount not working
    By Lukael in forum Programming
    Replies: 3
    Last Post: 03-25-2016, 01:38 AM
  3. Help with DCOUNT Function in Module
    By qcjustin in forum Access
    Replies: 9
    Last Post: 04-08-2015, 09:54 AM
  4. Dcount - Validation not working
    By princess12 in forum Access
    Replies: 12
    Last Post: 02-10-2015, 02:05 AM
  5. DCount function problem
    By 10 Gauge in forum Forms
    Replies: 5
    Last Post: 02-28-2011, 02:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums