Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 48
  1. #31
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    so what is the problem now? Selecting NCR puts 004 in NCRNumber which is what you wanted?



    I see the code has been moved to the form beforeupdate event and doesn't cater for if the user does not select an NCR type or selects CDR

    Also, you are not using the primary keys which is the intention for fast retrieval of data

  2. #32
    raychow22 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    145
    But when i select CDR, it does not dmx the CDR increments. It's just dmax whatever is on NCRnumber from tblNCR. I think ill just have to keep CDR and NCR tables and forms separate if i cant get this to work

  3. #33
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    because of your code

    at the moment it says

    Me.ncrnumber = Nz(DMax("[NCRNumber]", "tblNCR", "[NType]='NCR'"), 0) + 1

    it should say

    Me.ncrnumber = Nz(DMax("[NCRNumber]", "tblNCR", "[NType]='" & NType & "'"), 0) + 1

  4. #34
    raychow22 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    145

    Cool

    Quote Originally Posted by Ajax View Post
    because of your code

    at the moment it says

    Me.ncrnumber = Nz(DMax("[NCRNumber]", "tblNCR", "[NType]='NCR'"), 0) + 1

    it should say

    Me.ncrnumber = Nz(DMax("[NCRNumber]", "tblNCR", "[NType]='" & NType & "'"), 0) + 1
    Ajax! You are the best! It worked. Thanks!!!

  5. #35
    raychow22 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    145
    Ajax,

    Should I Put anything else in the afterupdate code to ensure that the Dmax function will always work for CDR or NCR? Right now I have it as

    Private Sub NType_AfterUpdate()


    Me.NCRNumber = Nz(DMax("[NCRNumber]", "tblNCR", "[NType]='" & NType & "'"), 0) + 1

    End Sub

  6. #36
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    no it will work for either. But you may need some code if the user was to select say NCR, then clears the control (i.e. make it null again)

    Also, you need to cater for the situation where more than one user is entering data - if two users enter an NCR at the same time, both will have the same number. Usually you would not assign a value until the form beforeupdate event (which is where you had the code in the db you posted) to minimise the time between assigning a value and updating the table.

  7. #37
    raychow22 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    145
    Quote Originally Posted by Ajax View Post
    no it will work for either. But you may need some code if the user was to select say NCR, then clears the control (i.e. make it null again)

    Also, you need to cater for the situation where more than one user is entering data - if two users enter an NCR at the same time, both will have the same number. Usually you would not assign a value until the form beforeupdate event (which is where you had the code in the db you posted) to minimise the time between assigning a value and updating the table.
    Yes! Ajax,

    I want to make sure that users do not duplicate the numberings if 2 or more were on at the same time. Is there anyway that this can happen? I split my database to front/back ends and I tested the front ends at the same time to see how the data will transfer to the backend. It seems that access sometimes makes a copy of the backend database if data is not successfully transferred over. Any suggestions would be nice. Thanks!

  8. #38
    raychow22 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    145
    Just a quick update on what I did... here's my code below. This prevents the DMAX working if it's not a new record which helps a little bit, but it will create duplicates... is there a way to error-proof this code?

    Private Sub NType_AfterUpdate()


    If Me.NewRecord = True Then
    Me.NCRNumber = Nz(DMax("[NCRNumber]", "tblNCR", "[NType]='" & NType & "'"), 0) + 1
    End If

    End Sub

  9. #39
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    as I explained - put the code into the form beforeupdate event rather than the control - but means the user won't know the number until the record is saved. That still leaves a very small change of two users saving at exactly the same time.

    To overcome that, create a multi field index of ntype and number and set allow duplicates to no

    so if the first user saves ok, the second user trying to save with the same number will generate an error. you can trap the error and save again having recalculated a new number. This is usually on a repeat loop in case there is more than two users involved

  10. #40
    raychow22 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    145
    Quote Originally Posted by Ajax View Post
    as I explained - put the code into the form beforeupdate event rather than the control - but means the user won't know the number until the record is saved. That still leaves a very small change of two users saving at exactly the same time.

    To overcome that, create a multi field index of ntype and number and set allow duplicates to no

    so if the first user saves ok, the second user trying to save with the same number will generate an error. you can trap the error and save again having recalculated a new number. This is usually on a repeat loop in case there is more than two users involved
    Ajax, I'm trying to create a multi-field index for ntype and number. Do I want to ignore the nulls set to "No" or "Yes".

    Also, is there a way to better ensure that data from the front end database gets to the backend database without Access having to create "duplicate" dbs because it could not successfully transfer the data into it.

  11. #41
    raychow22 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    145
    Ajax,

    I just want to make sure I did this correct. Here's a picture.
    Click image for larger version. 

Name:	8.png 
Views:	10 
Size:	23.8 KB 
ID:	29160

  12. #42
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    you shouldn't have any nulls so ignore = no

    don't understand what you mean by 'front end database'

  13. #43
    raychow22 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    145
    Do I need to create another field for the Indexes? "NTypeNumber" and then set "Duplicates to No?"

  14. #44
    raychow22 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    145
    Quote Originally Posted by Ajax View Post
    you shouldn't have any nulls so ignore = no

    don't understand what you mean by 'front end database'
    Front end database as in user interface side which include queries , forms and reports. Front end cannot modify tables. This is when I split the database to backend and frontend. Or do you think it's best to have one shared database where users will open the same file?

  15. #45
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    Do I need to create another field for the Indexes? "NTypeNumber" and then set "Duplicates to No?"
    No. It should look something like

    Click image for larger version. 

Name:	Capture.JPG 
Views:	12 
Size:	43.1 KB 
ID:	29164



    do you think it's best to have one shared database where users will open the same file?
    Absolutely not. Backend contains all tables, nothing else. And is stored in a mutually convenient folder for all users on the network. Front end contains everything else. Each user has their own copy of the front end linked to the backend. They do not share it otherwise there is risk of corruption.

Page 3 of 4 FirstFirst 1234 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 12
    Last Post: 12-25-2015, 12:47 AM
  2. DMAx Question for Report - DMax <= Dtae
    By crimedog in forum Access
    Replies: 8
    Last Post: 12-29-2014, 09:31 PM
  3. Replies: 4
    Last Post: 05-08-2014, 11:46 AM
  4. DMax with LIKE in criteria
    By tylerg11 in forum Access
    Replies: 5
    Last Post: 07-26-2013, 10:39 AM
  5. Replies: 6
    Last Post: 07-24-2012, 03:02 PM

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