Results 1 to 3 of 3
  1. #1
    drh is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Posts
    5

    VBA DCount() with variable field name

    Hello,

    I have the below code which performs an count on a specified field 'A-S1' in the database. Is it possible to supply a variable (strFC) in place of the static field name? I've tried doing this but I can't get the quotes correct.

    Any advice on this much appreciated!

    Best

    Drh



    Code:
    Public Function getNA(ByVal strSN, ByVal strMC, ByVal strT, ByVal strAC, ByVal strFC) As Integer
    
    On Error GoTo ErrorHandler
    
    getNA = DCount("[S_Number]", "TBL_MSA", _
                          "[S_Number] = '" & strSN & _
                          "' AND [M_Code] = '" & strMC & _
                          "' AND [T_Code] = '" & strTC & _
                          "' AND [A_S1] ='" & strAC & "'")
    ---

  2. #2
    pdebaets is offline Competent Performer
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Los Angeles
    Posts
    235
    This should work:

    getNA = DCount("[" & strFC & "]", "TBL_MSA", _
    "[S_Number] = '" & strSN & _
    "' AND [M_Code] = '" & strMC & _
    "' AND [T_Code] = '" & strTC & _
    "' AND [A_S1] ='" & strAC & "'")

  3. #3
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Are the Field Type integers or text.

    if it is Integer single quotes are not required.

    "' AND [M_Code] = '" & strMC

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

Similar Threads

  1. Using a field as a variable in a query
    By Shadow2K9 in forum Queries
    Replies: 1
    Last Post: 06-10-2010, 07:38 PM
  2. Refering to variable form names inside a variable
    By redpetfran in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 01:39 PM
  3. Replies: 2
    Last Post: 05-09-2010, 04:10 AM
  4. binding report field to variable
    By frente in forum Reports
    Replies: 1
    Last Post: 10-19-2009, 02:48 AM
  5. Can I have an input variable in a field formula
    By FeatherDust in forum Queries
    Replies: 3
    Last Post: 09-20-2009, 06:40 PM

Tags for this Thread

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