How to pad a field?

M

Me

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
 
M

Me

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
 

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