Results 1 to 4 of 4
  1. #1
    msasan1367 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2013
    Posts
    60

    enter ID automatically or manually

    I have a field named ID, now I want this:
    I can enter any ID or If I don't enter ID on it, it creates an ID automatically according to (MAX ID + 1: example: the MAX ID is 400 now ID gets 401)

  2. #2
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742

    Google Custom Counter or Custom Autonumber for Solutions - Here's useful samples

    Since you want to occasionally control it, you can't use autonumber. You can google for "Custom Autonumber" or "Custom Counter" to get various solutions. Here's three useful pages to get you started.

    http://support.microsoft.com/kb/210194
    http://msgroups.net/microsoft.public...onumber/133479
    http://www.office-archive.com/3-ms-a...a062aaa733.htm

    Hopefully, this should be enough info for you to mark the thread solved.

  3. #3
    msasan1367 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2013
    Posts
    60
    I solve it with this code:
    Code:
    Dim srchID, createID As String
    srchID = DLookup("masaleh_ID", "blook_masaleh_tbl")
    If (srchID) Then
        createID = DMax("masaleh_ID", "blook_masaleh_tbl")
        Me.IDtxt.Value = createID + 1
    Else
        Me.IDtxt.Value = 1
    End If

  4. #4
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742

    Not Quite Right yet...

    The code doesn't look right. You don't have a where condition on your Dlookup, so that command is checking for ANY record in that table, in no particular order.

    Here's a page that explains what Dlookup does - http://www.techonthenet.com/access/f...in/dlookup.php

    What that particular code will do is to bring back the first value for Masaleh_ID that exists in the table, which is stored/returned by Access in random order, and put that value into srchID. If there are NO values for Masaleh_ID, it will put a NULL in that spot.

    Next, if srchID is NULL, "If (SrchID)" most likely will throw an error, so the else condition that sets Me.IDtxt.value to 1 will never be reached.

    Before I post any suggestions, let me ask you how you expect the calling form to operate. Is the operator putting the ID he wants into IDtxt? When/how does a new ID get added to blook_masaleh_tbl? How does the calling form know that the form is supposed to default to a newly created ID?

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

Similar Threads

  1. Automatically enter today's date when entering time
    By Szabi in forum Database Design
    Replies: 5
    Last Post: 03-16-2012, 03:50 AM
  2. Manually autonumber a field
    By apsf68 in forum Access
    Replies: 15
    Last Post: 11-13-2010, 04:04 PM
  3. Manually changing attribute
    By michaeljohnh in forum Programming
    Replies: 4
    Last Post: 09-14-2010, 12:50 PM
  4. How do I enter data automatically?
    By ffurqana in forum Access
    Replies: 0
    Last Post: 07-08-2010, 07:47 PM
  5. Replies: 1
    Last Post: 06-10-2010, 10:47 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