Results 1 to 9 of 9
  1. #1
    MintChipMadness is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    109

    Dmax/Val function Problem

    I am having trouble with some code. I know how to write the expression in access but I can't figure out how to translate it to VBA. I listed the code below. The Val portion extracts just the numbers from [Boxes].[OldBox#]. Then DMax finds the highest number and adds 1 to it. Lastly, the current record will be set to that number. Thank you for your help.



    Me.[OldBox#]=DMax("Val([OldBox#])","[Boxes]")+1

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    What is the trouble - error message, wrong result, nothing happens?

    I tested that expression in the VBA editor immediate window and it worked.
    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.

  3. #3
    MintChipMadness is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    109
    It says Run-time error '3464': Data type mismatch in criteria expression.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    OldBox# is a text type and result is a number but the text field should have no problem accepting that value. I did another test and the field was populated with the result.

    Since I can't replicate the issue, will need your latest version of db to analyse your code.

    Don't want a letter suffix on the value?
    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.

  5. #5
    MintChipMadness is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    109
    Some of the old box numbers have letters in them. I use the Val function to make sure the boxes with letters are not higher than the numbers. I attached the database. The code is on the DataEntry Form. What I want to do is fill in the OldBox# for the a new record. The information comes from the DataEntry Query which is the record source of the form.
    Attached Files Attached Files

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    This is annoying. The DMax/Val works in the Immediate window but bombs in the VBA procedure.

    1. Change the DataEntry query to create a field with calculation to extract the number from OldBox#:
    OldBoxNumber: Val([OldBoxNumber])

    2. Change the code to:
    Me.[OldBox#] = DMax("[OldBoxNumber]", "[DataEntry]") + 1

    That all works but now get 'Action Failed' macro execution error from the Save button click. I don't use macros so will let you deal with that.
    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.

  7. #7
    MintChipMadness is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    109
    Thank you.I'll fix that save button. On my real database, I converted all the macros to VBA. Just curious why didn't he VAL function work nested in the Max function?

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I don't know why, that was source of my frustration. The nesting worked in the Immediate window test but not in the event procedure.
    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.

  9. #9
    MintChipMadness is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    109
    I figured it out without using the work around. I thought I tried it but I guess I didn't. I changed the domain from Boxes to DataEntry and it worked.

    Me.[OldBox#] = DMax("Val([OldBox#])", "[DataEntry]") + 1

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

Similar Threads

  1. Replies: 6
    Last Post: 07-24-2012, 03:02 PM
  2. 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
  3. append query: dlookup or dmax problem
    By jeffr27 in forum Queries
    Replies: 1
    Last Post: 05-10-2011, 09:25 AM
  4. Problem with IIF function
    By Hulk in forum Forms
    Replies: 3
    Last Post: 03-20-2011, 12:59 PM
  5. VBA Function problem
    By smikkelsen in forum Programming
    Replies: 5
    Last Post: 07-16-2010, 07:46 AM

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