Results 1 to 6 of 6
  1. #1
    timmy is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    62

    Using Nz and Dmax

    Hi everyone

    I recently converted my DB backend from MySQL to access (was having stability issues).

    In MySQL, i had set my primary key to start at 2000 and auto-increment from there. Converting it back, obviously i now can't use auto-number.

    The primary key is used as a reference for the call (its a call management DB). I know i'm not supposed to expose the user to a PK or use it for anything but internal referencing, but unfortunately i didn't stick to that.

    Now obviously before, when i entered a new workorder, it would automatically go to the next number, now i need this to happen with the new access backend.

    I have entered this as the control source on the form for workorderID:
    Code:
    =Nz(DMax([WorkorderID],[Workorders]),0)+1
    Im getting a circular reference error when in design view and the always helpful #Name when in form view.

    Any help would be appreciated .

    Thanks a lot.

    Edit: I just realised, i view workorders as well as create them, using the same form. Heres the code i use to determine if we are viewing or creating:
    Code:
           If Forms![Workorders by Customer]![Workorders by Customer Subform].Form.RecordsetClone.RecordCount > 0 Then
               DoCmd.GoToControl "WorkorderID"
               DoCmd.FindRecord Forms![Workorders by Customer]![Workorders by Customer Subform].Form![WorkorderID]
           End If
    Should i be adding the Nz(Dmax) functions into that code, rather than the control on the form?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Hi

    This works for me when used as the Defult Value of the WorkorderID field.
    Code:
     
    =Nz(DMax("[WorkorderID]","[Workorders]"),0)+1
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    timmy is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    62
    Doesn't work for me, i get a circular reference error. I have relationships set up correctly... Not sure whats going on here.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Hi
    A couple of questions:

    1 Are you sure you are putting the code in the "Default Value" property of the "WorkorderID" field?

    2 Is this a multi user app with each user having there own front end?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    timmy is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    62
    1 Are you sure you are putting the code in the "Default Value" property of the "WorkorderID" field?
    Sorry, i was being dumb and putting it in the control value. It works when put into the default value.

    2 Is this a multi user app with each user having there own front end?
    It's shared on a network drive, viewed by a few but data only entered by 1 person at any time.

    So now i have a progressing workorderID that i wanted, however it doesnt work alongside my "check if its a new workorder, or if we are viewing an existing workorder" code. I have tried this(it doesnt work):

    Code:
    If Forms![Workorders by Customer]![Workorders by Customer Subform].Form.RecordsetClone.RecordCount > 0 Then
        DoCmd.GoToControl "WorkorderID"
        DoCmd.FindRecord Forms![Workorders by Customer]![Workorders by Customer Subform].Form![WorkorderID]
    Me.WorkorderID=Nz(DMax([WorkorderID],[Workorders]),0)+1
    End If

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Hi

    It's shared on a network drive, viewed by a few but data only entered by 1 person at any time.
    I'm not sure if this means it is or isn't split. If it is not, it should be, to avoid coruption of the app.

    If data is ever added by more that one at the sane time, you will need to use a different method to create the ID number. Maybe as the record is saved instead of when it is first being created, otherwise both users will be trying to create a new record with the same ID.

    I'm not sure what you want to do in the code that you posted but perhaps it would be better to check if it is a new record in the form's on current property.
    Code:
     
    If Me.NewRecord = True Then
       What you want to do goes here
    End If
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. append query: dlookup or dmax problem
    By jeffr27 in forum Queries
    Replies: 1
    Last Post: 05-10-2011, 09:25 AM
  2. DMAX syntax
    By tuyo in forum Programming
    Replies: 1
    Last Post: 03-24-2011, 12:15 AM
  3. Switching from string to a number using Dmax
    By dsheets05 in forum Access
    Replies: 3
    Last Post: 12-15-2010, 03:07 PM
  4. DMax Condition
    By Luis Ferreira in forum Forms
    Replies: 3
    Last Post: 11-05-2010, 09:48 AM
  5. DMax returning wrong value
    By nedbenj in forum Access
    Replies: 7
    Last Post: 10-24-2007, 10:30 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