Dropping Leading Zero

S

Sash

I have an unbound field with textbox. The user will key in text similar to
"02691567". I run a bunch of other imports, filecopy, etc, but want to put
this number in my table. The following works, but keeps dropping the leading
zero. Few things that may help. dbo_ImagesS is a SQL Server database and
the field SNum is a char. I feel like I've tried everything...including my
last attempt to format it as text. Any directions as always is deeply
appreciated.

'3 - Update the field SNum
Dim strSQL2 As String
strSQL2 = "UPDATE dbo_ImageS SET SNum = " & Format(Me!SNum, Text) & " WHERE
SNum is Null"
DoCmd.RunSQL strSQL2
 
D

Douglas J. Steele

How long is it supposed to be?

Assuming 8 digits, try either

Format(Me!SNum, "00000000")

or

Right("00000000" & Me!SNum, 8)
 
S

Sash

Okay. Revised my code a bit and it still doesn't work. When I view it in
the debug window it shows the leading zero. Something so simple shouldn't be
this difficult. (Can you tell I'm frustrated?) I also tried format as you
have below, but neither that or Right worked.

Dim strSQL2 As String
Dim strSiloNum As String
strSiloNum = Right("00000000" & Me!SiloNum, 8)
strSQL2 = "UPDATE dbo_ImageSilo SET SiloNum = " & strSiloNum & " WHERE
SiloNum is Null"
DoCmd.RunSQL strSQL2
 

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