My code keeps dropping the leading zeroes from a text string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shawn29316
    New Member
    • Feb 2007
    • 33

    My code keeps dropping the leading zeroes from a text string

    I stripped out some stuff but the code that matters is:
    Code:
    Private Sub Command18_Click()
    DoCmd.RunSQL "Update T_JB_InputData Set Position = " & Me.BidJobCode.Value
    End Sub
    I put a message box in to display the value and it showed the leading zeroes but when I look at the text field I'm trying to update, the zeroes are missing.

    I'd appreciate any help you can give me!

    Shawn
    Last edited by NeoPa; Jan 20 '16, 11:59 PM. Reason: Put the code in the [CODE] tags
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    String literals need to be surrounded by single quotes.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      SQL will interpret any value without delimiters (Quotes or hashes.) as a simple numeric value. For a string value, as opposed to a numeric one, you'd want the SQL quotes (') around the value.
      Code:
      Private Sub Command18_Click()
          DoCmd.RunSQL "UPDATE [T_JB_InputData] SET [Position] = '" & Me.BidJobCode.Value & "'"
      End Sub
      Of course, if the field [Position] is defined as numeric then even that won't do it. Expecting a numeric field to hold string data just doesn't make any sense.

      Comment

      • Shawn29316
        New Member
        • Feb 2007
        • 33

        #4
        NeoPa,
        Thanks for your help. I thought the issue had to do with quotes and I'd be ashamed to tell you how many places I had tried to put them.....just not the right place.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          LOL.

          Sometimes an example/illustration is the best way to get something across. I'm pleased we were able to help anyway :-)

          Comment

          Working...