Setting A Formatted Value To A Control

  • Thread starter Thread starter Bob Gardner
  • Start date Start date
B

Bob Gardner

I have a form frmDrawings that contains a bound field
[ID]. The field is an autonumber with a 0000 format so
that "1" displays as "0001" and so on.

When a new record is created with the form I want to be
able to set the value of [DocumentID] on the form to 'DWG'
& [ID] to display "DWG0001". The control is updated but
displays and saves as "DWG1". How can I get it to read
as "DWG0001"?

Function AssignID()
On Error GoTo AssignID_Err

Forms!frmDrawings!DocumentID = 'DWG' & Forms!
frmDrawings!ID


AssignID_Exit:
Exit Function

AssignID_Err:
MsgBox Error$
Resume AssignID_Exit

End Function

Any help is appreciated.
Bob
 
Try:
Forms!frmDrawings!DocumentID = 'DWG' &
format(Forms!frmDrawings!ID,"0000")

if the code is running in the form, you can use:


me!documentID = 'DWG' & format(me!ID,"0000")

You should also note that you could also just display the above expression
and not actually store it.

In addition, it is usually a bad idea to expose the autonumber id. (just be
aware that you can get gaps in it, and it is not always sequential in
nature).
 
Back
Top