Results 1 to 3 of 3
  1. #1
    TamworthBob is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    May 2020
    Posts
    7

    DCount with two separate fields in the same table

    I have a form (frmCRMEditRF)with a textbox (txtActionNumber) and a subform (CRMPartsRF) with a combo box (cboPartNumber).
    I need to check the records in tblRepReport table to check if a record has already been saved by looking to see if there is a record with the contents of txtActionNumber (saved RPIdentifier inthe table)and cboPartNumber (saved in ProductID) that match those in the open form (frmCRMEditRF)
    txtActionNumber has input similar to text + date eg computer020520, making it a text field. cboPartNumber records an autonumber eg1426
    I have tried dozen of code examples without success
    MY CODE"
    Dim CHKID As String
    Dim CHKProdID As Long
    Dim Tot As Double



    CHKID = Me!txtActionNumber
    CHKProdID = Me!frmCRMPartsRF!cboPartNumber

    'Tot = DCount("[RepReportID]", "tblRepReport", "[ProductID] = CHKProdID" And "[RPIdentifier] = '" & CHKID & "'")


    If Tot > 0 Then
    MsgBox "This record already exists", vbOKOnly + vbExclamation, "Duplicate Record"
    End If
    Thanks in advance
    Bob

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    count with asterisk field,
    the form fields must be outside of the quotes to resolve, (you dont need the ME, but it shows better to show form objects)
    numeric fields dont get delimiters, strings get single quote, dates get #. (here ProdID is numeric, ChkID is string, correct?)

    = DCount("*", "tblRepReport", "[ProductID] = " & me.CHKProdID & " And [RPIdentifier] = '" & me.CHKID & "'")

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,537
    Can you confirm the following:

    1) ProductID is a numeric field in tblRepReport

    2)
    RPIdentifier is a text field in tblRepReport

    3) You haven't made any spelling mistakes in DCount()

    Where are you using this code.
    I have tried dozen of code examples without success

    What does that mean? Code doesn't run. Throws errors
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Replies: 2
    Last Post: 08-13-2019, 10:32 AM
  2. Replies: 4
    Last Post: 07-11-2016, 01:11 PM
  3. Replies: 18
    Last Post: 05-07-2015, 10:59 AM
  4. How to separate names into 2-separate fields
    By djclntn in forum Queries
    Replies: 4
    Last Post: 09-18-2014, 02:34 PM
  5. Replies: 12
    Last Post: 12-14-2011, 08:04 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