Start simple and build:
1. Create a table with two columns:
POID
PODate
2. Create a form from the table using the form wizard.
3. Change the two textbox names on the form to:
txtPOID
txtPODate
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
Me![txtPOID].Requery
Case 6000
Me![POID] = 50000
Me![txtPOID].Requery
Case Else
Me![POID] = lngID
Me![txtPOID].Requery
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.
Regards,
Bob
|