How to Convert Autonumber to Text

G

Guest

I have: A form with FieldA as an autonumber.

I want: When a new record is created, FieldB will be populated with a
3-character text equivalent of the autonumber. (e.g., 5 -> 005, 12 -> 012,
136 -> 136).
 
M

Marshall Barton

DevDaniel said:
I have: A form with FieldA as an autonumber.

I want: When a new record is created, FieldB will be populated with a
3-character text equivalent of the autonumber. (e.g., 5 -> 005, 12 -> 012,
136 -> 136).


Why? There is no reason to save the same information twice.
You can display the autonumber field with leading zeros
simply be formatting it.

Note that displaying an autonumber field to users is almost
always a really bad idea.
 
G

Guest

DevDaniel said:
I have: A form with FieldA as an autonumber.

I want: When a new record is created, FieldB will be populated with a
3-character text equivalent of the autonumber. (e.g., 5 -> 005, 12 -> 012,
136 -> 136).

An alternative question is: How do you create a three-character text field
that auto-increments each time a new record is created?
 
P

Pieter Wijnen

Keep it Numeric & Use the Format Property to Display it

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim i As Long
i = Nz(Access.DMax("MyID","MyTable"),0) +1
Me.MyID.Value = i
End Sub

HtH

Pieter
 

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