Dmax error: 2471

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • barmatt80
    New Member
    • Dec 2007
    • 55

    Dmax error: 2471

    Ran into a problem, just as I thought I had it working.

    Code:
    Dim strCurrentFiscalYear As String
        strCurrentFiscalYear = DLookup("[CurrentFiscalYear]", "YearReset", "[ID] = 1")
    Dim strLastFiscalYear As String
        strLastFiscalYear = strCurrentFiscalYear - 1
    strNewRecordNumber = DMax("[RecordNumber]", "TblDocket", "[FiscalYear] = strLastFiscalYear") + 1
    The problem I am running into is the strLastFiscalYe ar in the DMax field. The error I get is: Run Time error: 2471....The expression you entered as a query parameter produced this error: 'strLastFiscalY ear'

    What I am trying to accomplish is that for instance that the current fiscal year is 2009 saved in table named YearReset, in the field CurrentFiscalYe ar. When a user tries to enter a record for the last fiscal year - 2008, the dmax is or should look in the database table TblDocket, find the largest RecordNumber of the record that the Fiscalyear equals 2008.

    I can get it to work if I would just put 2008 where strLastFiscalYe ar is but that would not help for next years.

    Any suggestions? Thanks again.
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Originally posted by barmatt80
    Ran into a problem, just as I thought I had it working.

    Code:
    Dim strCurrentFiscalYear As String
        strCurrentFiscalYear = DLookup("[CurrentFiscalYear]", "YearReset", "[ID] = 1")
    Dim strLastFiscalYear As String
        strLastFiscalYear = strCurrentFiscalYear - 1
    strNewRecordNumber = DMax("[RecordNumber]", "TblDocket", "[FiscalYear] = strLastFiscalYear") + 1
    The problem I am running into is the strLastFiscalYe ar in the DMax field. The error I get is: Run Time error: 2471....The expression you entered as a query parameter produced this error: 'strLastFiscalY ear'

    What I am trying to accomplish is that for instance that the current fiscal year is 2009 saved in table named YearReset, in the field CurrentFiscalYe ar. When a user tries to enter a record for the last fiscal year - 2008, the dmax is or should look in the database table TblDocket, find the largest RecordNumber of the record that the Fiscalyear equals 2008.

    I can get it to work if I would just put 2008 where strLastFiscalYe ar is but that would not help for next years.

    Any suggestions? Thanks again.
    Hi

    Try this

    Dim strLastFiscalYe ar As String

    strLastFiscalYe ar = strCurrentFisca lYear - 1

    strNewRecordNum ber = DMax("[RecordNumber]", "TblDocket" , "[FiscalYear] = " & strLastFiscalYe ar) + 1

    strLastFiscalYe ar is a variable, you have made part of a literal string (it need concatenating into the string as above).

    Also, I think 'strCurrentFisc alYear', 'strLastFiscalY ear' and 'strNewRecordNu mber' should be Integers not a strings ??


    MTB

    Comment

    • barmatt80
      New Member
      • Dec 2007
      • 55

      #3
      thanks mike! worked great. yes they should be integers. I am working on changing them now.

      thanks again

      Comment

      Working...