Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with DCount, Getting #Name? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8))

    I have the following code in an unbound text box on a Main Form:


    =DCount("tblVouch2.idsKeyOfVouch2","tblVouch2","[tblVouch2.strBatchNo]="
    & Chr(34) & [Me].[strBatchNo] & Chr(34)
    & " and [tblVouch2.strREF]=" & Chr(34) & [Me].[strREF] & Chr(34)
    & " and [tblVouch2.strVSS]=" & Chr(34) & [Me].[strMPSS] & Chr(34)
    & " and [tblVouch2.strDRVSS]=" & Chr(34) & [Me].[strDSS] & Chr(34))


    and it is displaying #Name

    What am I doing wrong?

    Thanks, John

    PS: I have the following similar code in a SubForm on the above Main Form that works OK

    <pre>Private Sub Form_BeforeInsert(Cancel As Integer)

    Dim lngLineCount As Long

    lngLineCount = DCount("tblVouch2.idsKeyOfVouch2", "tblVouch2", _
    "[tblVouch2.strBatchNo]=" & Chr(34) & Me.Parent![strBatchNo] & Chr(34) & _
    " and [tblVouch2.strREF]=" & Chr(34) & Me.Parent![strREF] & Chr(34) & _
    " and [tblVouch2.strVSS]=" & Chr(34) & Me.Parent![strMPSS] & Chr(34) & _
    " and [tblVouch2.strDRVSS]=" & Chr(34) & Me.Parent![strDSS] & Chr(34))

    If lngLineCount >= GetPref("Maximum Lines Per Check") Then '21
    MsgBox "There are " & lngLineCount & " line items for this Batch, " & _
    "Member and Dentist, Maximum line items per check is " _
    & GetPref("Maximum Lines Per Check") & _
    " Save remaining items for next Batch."
    Cancel = True
    Exit Sub
    End If

    End Sub
    </pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Help with DCount, Getting #Name? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8))

    What happens if you omit all those square brackets?
    And if you omit <code>tblVouch2.</code> ?

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with DCount, Getting #Name? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8))

    Same #Name error

    =DCount("idsKeyOfVouch2","tblVouch2","strBatchNo=" & Chr(34) & [Me].[strBatchNo] & Chr(34)
    & " and strREF=" & Chr(34) & [Me].[strREF] & Chr(34)
    & " and strVSS=" & Chr(34) & [Me].[strMPSS] & Chr(34)
    & " and strDRVSS=" & Chr(34) & [Me].[strDSS] & Chr(34))


    This worked OK in sub form

    lngLineCount =
    DCount("idsKeyOfVouch2", "tblVouch2", "strBatchNo=" & Chr(34) & Me.Parent![strBatchNo] & Chr(34)
    & " and strREF=" & Chr(34) & Me.Parent![strREF] & Chr(34)
    & " and strVSS=" & Chr(34) & Me.Parent![strMPSS] & Chr(34)
    & " and strDRVSS=" & Chr(34) & Me.Parent![strDSS] & Chr(34))

    Any other thoughts?

    John

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Help with DCount, Getting #Name? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8))

    Remove <code>[Me].</code>

    Me is only valid in VBA, not in the control source of a text box.

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with DCount, Getting #Name? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8))

    Perfect!

    Thanks

Posting Permissions

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