How to pad a field?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a need to store a field in the database as
say 'D0001'.

Can someone please help me writing the code, I have
written the following and I am getting error (rightly) for
CAST, but I don't know what to use instead.

dim no as Integer
DoCmd.RunSQL ("select max(TEMP_NUM) into no from Prod_file where filing_area
= [FILING_AREA]")
[Temp_num] = no + 1
If [FILING_AREA] = "D" Then
[CONTRACT_NUM] = "D" + Right("00000000" + CAST(Temp_num, 8), 8)
End If

In this example it should appear something like 'D0000100'
'D0001001'

Thank you in advance!
-M
 
Thank you Doug!
-M

Douglas J. Steele said:
[CONTRACT_NUM] = "D" & Format(Temp_Num, "00000000")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Me said:
I have a need to store a field in the database as
say 'D0001'.

Can someone please help me writing the code, I have
written the following and I am getting error (rightly) for
CAST, but I don't know what to use instead.

dim no as Integer
DoCmd.RunSQL ("select max(TEMP_NUM) into no from Prod_file where filing_area
= [FILING_AREA]")
[Temp_num] = no + 1
If [FILING_AREA] = "D" Then
[CONTRACT_NUM] = "D" + Right("00000000" + CAST(Temp_num, 8), 8)
End If

In this example it should appear something like 'D0000100'
'D0001001'

Thank you in advance!
-M
 
Back
Top