leading zeroes in VBA

R

R Makos

I am trying to write some VBA code in Access. If I use the literal "031" as
the VALUE in the VBA Insert INTO command, the zero is preserved. I have a
VBA string variable that when displayed, contains the leading zero. If I
move the "031" to this VBA string variable and then do the INSERT, the
leading zero is lost. The Access field is defined as TEXT length of 3. The
VBA variable is STRING * 3.

I've tried lots of convert and format functions to no avail.
 
D

Douglas J Steele

Posting your code would be a good idea...

Are you remembering to put quotes around your variable in your INSERT INTO
command?

strSQL = "INSERT INTO MyTable(MyField) " & _
"VALUES ('" & strMyValue & "')"

Exagerated for clarity, that's


strSQL = "INSERT INTO MyTable(MyField) " & _
"VALUES ( ' " & strMyValue & " ' ) "
 

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