Newbie, If Statement & Run Time Error 424

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BlackEyedPea
    New Member
    • Dec 2009
    • 9

    Newbie, If Statement & Run Time Error 424

    Hi,
    I'm importing a text file which contains a barcode. Once imported I add a column to the table & copy the barcode into the new column (So far I've done all of this using code).

    I want to re-format the new column so that all the barcodes are 13 digits long (some are 7, some are 6 etc, etc). Where any barcodes are not 13 digits long, I want to add leading zero's until they are all 13 digits long. This is where I'm getting stuck. I wrote a real basic piece of code but when I run it I get a "run time error 424, "Object Required" message.

    Here is an example of what I wrote:

    Code:
    Function Test()
    Dim OneZero As String
    Dim TwoZero As String
    OneZero = "0"
    TwoZero = "00"
    
    If Len(AllTitles.[ASDABarcode]) = 12 Then
    AllTitles.[ASDABarcode] = OneZero & AllTitles.[ASDABarcode]
    End If
    End Function
    I'm a complete novice really just trying to learn some basics in coding etc to maybe help automate some tasks; so any help or guidance will be appreciated.
    Thanks,
    BEP
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by BlackEyedPea
    Hi,
    I'm importing a text file which contains a barcode. Once imported I add a column to the table & copy the barcode into the new column (So far I've done all of this using code).

    I want to re-format the new column so that all the barcodes are 13 digits long (some are 7, some are 6 etc, etc). Where any barcodes are not 13 digits long, I want to add leading zero's until they are all 13 digits long. This is where I'm getting stuck. I wrote a real basic piece of code but when I run it I get a "run time error 424, "Object Required" message.

    Here is an example of what I wrote:

    Code:
    Function Test()
    Dim OneZero As String
    Dim TwoZero As String
    OneZero = "0"
    TwoZero = "00"
    
    If Len(AllTitles.[ASDABarcode]) = 12 Then
    AllTitles.[ASDABarcode] = OneZero & AllTitles.[ASDABarcode]
    End If
    End Function
    I'm a complete novice really just trying to learn some basics in coding etc to maybe help automate some tasks; so any help or guidance will be appreciated.
    Thanks,
    BEP
    Execute the following UPDATE Query:
    Code:
    Dim strSQL As String
    
    strSQL = "UPDATE AllTitles SET [ASDABarcode] = Format([ASDABarcode], '0000000000000');"
    
    CurrentDb.Execute strSQL, dbFailOnError
    Before Executing Query:
    Code:
    ASDABarcode
    1
    12
    123
    1234
    12345
    123456
    1234567
    12345678
    123456789
    1234567890
    12345678901
    123456789012
    1234567890123
    After Executing Query:
    Code:
    ASDABarcode
    0000000000001
    0000000000012
    0000000000123
    0000000001234
    0000000012345
    0000000123456
    0000001234567
    0000012345678
    0000123456789
    0001234567890
    0012345678901
    0123456789012
    1234567890123

    Comment

    • BlackEyedPea
      New Member
      • Dec 2009
      • 9

      #3
      ADezii, you are a god amongst men! You would probably laugh if you knew how much time I'd spent trying to do that, & you manage it in minutes!
      Thanks very much, really appreciate it.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        Learning curves are always steepest at the start. Stick with it & you'll find it all so much easier in a short while :)

        Welcome to Bytes!

        Comment

        Working...