Results 1 to 4 of 4
  1. #1
    AgentLozen is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    2

    DMax function Help

    Hi everyone.



    I've been learning Access recently and I've come across a problem that's stopped me dead in my tracks. It seems like this should be OMEGA LEVEL EASY, but instead it's giving me a ton of trouble. Here's the situation.

    I have a table "ASSIGNMENTS" whose primary key "ASSIGNMENT ID" I'm changing from Auto-Number -> a DMax numbering convention. All of the table information is entered through a form [ASSIGNMENT ENTRY]. I want the form to have a button that, when clicked, puts the Dmax value of the primary key into a text box "txtTest".

    The table "ASSIGNMENTS" primary key "ASSIGNMENT ID" has data in the Number format like this:
    1, 2, 3, 4, 5, 6, 7, 8

    My VB code for the button looks like:
    [Forms]![ASSIGNMENT ENTRY]![txtTest] = DMax("ASSIGNMENT ID", "ASSIGNMENTS")
    The control source for txtTest is the "ASSIGNMENT ID" column.

    I expect the output to the text box to be 8. Then 8 should appear in the ASSIGNMENTS table when I save the record. Instead, I'm getting the error "Syntax error (missing operator) in query expression 'Max(ASSIGNMENT ID)'. I can feed an arbitrary number into the button like "130". That works and changes the value of the text box to "128". The trouble seems to be with the DMax function itself.

    Has anyone experienced a problem like this before and has some advice to offer? I would appreciate the help.

    -AgentLozen

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,180
    try DMax("[ASSIGNMENT ID]", "ASSIGNMENTS") with square brackets. You have used a space in a fieldname, which is never a good idea.
    Also, if you want to assign a new ID-value which has to be unique, I think you probably want to set it to DMax("[ASSIGNMENT ID]", "ASSIGNMENTS") + 1

    Kind regards
    Noëlla

  3. #3
    AgentLozen is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    2
    Oh wow. That did it.
    I guess using spaces makes things needlessly complicated. I'll keep that in mind in the future.
    I appreciate your help Noella.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Advise no punctuation/special characters (underscore only exception) as well. Camel case is best for easy reading, such as: AssignmentID.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. VBA DMax function
    By edson in forum Access
    Replies: 9
    Last Post: 01-31-2015, 10:11 AM
  2. ?? on DMAX function
    By eliotchs in forum Programming
    Replies: 4
    Last Post: 07-28-2014, 03:35 PM
  3. Dmax/Val function Problem
    By MintChipMadness in forum Programming
    Replies: 8
    Last Post: 08-13-2012, 08:50 AM
  4. Replies: 6
    Last Post: 07-24-2012, 03:02 PM
  5. using a qry to run a report with Dmax Function
    By mrjoshuaw in forum Access
    Replies: 6
    Last Post: 02-01-2012, 07:29 AM

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