New Record

Y

Yogi

Please help me,,i'm new in ms acces 2003

I have a Form that have a Field called
Code:
,,,i want this field is
automatically inserted with the last record code's +1,,for the first record i
want to use code like A0001,,,after i save it and want to add new record the
field is automatically inserted with A0002,, and it only changed when i want
to add new record.

thanks for your help :)
 
L

Linq Adams via AccessMonster.com

This hsould do what you want:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
If RecordsetClone.RecordCount = 0 Then
Me.Code = "A0001"
Else
Me.Code = "A" & Format(DMax("val(Right(
Code:
,4))", "YourTableName") + 1,
"0000")
End If
End If
End Sub

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003


http://www.accessmonster.com/Uwe/Forums.aspx/access-gettingstarted/201001/1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top