Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 25th, 2003, 03:46 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts

Start simple and build:

1. Create a table with two columns:


2. Create a form from the table using the form wizard.

3. Change the two textbox names on the form to:


txtPOID’s control source is POID, txtPODate’s control source is PODate.

4. Set txtPOID’s Enabled property to No.

5. Paste this behind the form:

Private Sub Form_BeforeInsert(Cancel As Integer)

   Dim strID As String
   Dim lngID As Long

   lngID = Nz(DMax("[POID]", "tblPurchaseOrders") + 1, 1)

   Select Case lngID
      Case 60000
         Me![POID] = 500000
      Case 6000
         Me![POID] = 50000
     Case Else
         Me![POID] = lngID
     End Select

End Sub

I added the Nz function so the code will run if the table is empty.

6. Open the form.

7. Start typing a date. The POID should fill in for you.

8. Close the form.

9. Add the following record to the table: 5999, 1/1/2001

10. Open the form

11. Start typing a date. The POID should change to 50000.



Similar Threads
Thread Thread Starter Forum Replies Last Post
Autonumber in Microsoft Access ozzii Classic ASP Databases 1 January 17th, 2007 04:08 PM
autonumber problem in Access Pat Crotty Access VBA 2 September 6th, 2006 10:37 AM
Access Autonumber chall90909 Access ASP 1 November 21st, 2004 10:26 AM
Autonumber on Access 2002 pdunning Access 1 August 23rd, 2004 10:33 AM
Mixing Data access logic and business logic polrtex BOOK: Professional Jakarta Struts 0 December 15th, 2003 07:19 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.