Results 1 to 8 of 8

Thread: Dmax

  1. #1
    Join Date
    Apr 2004
    Posts
    182

    Unanswered: Dmax

    I am getting a type mismatch error when I try to use the following code . Can anyone help.

    MyCTD = DMax("CTD_number", "tbldrawings") + 1

    I have also tried it using criteria but I'm not really sure what criteria to use.
    I wan to assign the next number to my CTD_Number field.

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Three things come to mind, first try using brackets around the field name. Second, what is the datatype of CTD_number? Third, what is the datatype of MyCTD?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Apr 2004
    Posts
    182
    CTD_NUmber is nvarchar 10, MYCTD is Variant

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    CTD_Number needs to be a numeric datatype. You're not going to get the result you expect otherwise.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Oct 2003
    Location
    US
    Posts
    343
    change your code like this

    MyCTD = Cint(DMax("CTD_number", "tbldrawings")) + 1

    That should do it.

  6. #6
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Quote Originally Posted by khan
    change your code like this

    MyCTD = Cint(DMax("CTD_number", "tbldrawings")) + 1

    That should do it.

    What if CTD_number is "b543CH" ?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  7. #7
    Join Date
    Apr 2004
    Posts
    182
    Quote Originally Posted by Teddy
    CTD_Number needs to be a numeric datatype. You're not going to get the result you expect otherwise.

    The reason I am using nvarchar is that to start with I have a default value of NCTD meaning there is no number assigned then later I assign an automatic number which is what I am trying to do with DMax. perhaps there is a better way to do it

  8. #8
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Yeah, that's going to screw you up pretty good. Just leave it null by default. If you need to return the NCTD tag for null values, use nz([CTD_number], "NCTD")
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Posting Permissions

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