Update Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Basenji3
    New Member
    • Mar 2014
    • 14

    Update Query

    I have a simple update query that should apply numbers to a text field, but it keeps dropping the leading zero. Should be 054846, but ends up as 54846. Can't figure out what I'm missing.

    Code:
    Dim strsql As String
    strsql = "UPDATE [Action]" _
           & "SET [Action] = (" & "054846" & ")"
    
    DoCmd.RunSQL strsql
    I can't afford to pull anymore hair out, appreciate any help. Thanks.
  • Luk3r
    Contributor
    • Jan 2014
    • 300

    #2
    This is because your column is an integer column. 054846 is a string, 54846 is an integer. To keep the leading zero(s), you would have to change the column type to char (nchar, nvarchar, etc.). If this is not an option and the string is strictly for client-side application viewing, you could always format the string at the application layer.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Actually, I believe the situation is the reverse. It sounds like the field in the table is defined as a string. But the SQL you have has the number as an integer because you didn't surround the value with single quotes. You will see the issue if you output the SQL string you're trying to run.

      Comment

      • Basenji3
        New Member
        • Mar 2014
        • 14

        #4
        Thanks for the help, I forgot to post the response some time ago.

        Comment

        Working...