Skip to main content

Search

Search

To Restart Serialization If A Db Feild Change

Comments

6 comments

  • Avatar
    Legacy Poster

    If possible, add an extra column to your database called "Start Num" and just set them all to 1. Then link the counter field to this and it should restart to 1 for each new record.

    0
  • Avatar
    Domingo Rodriguez
    Moderator

    Find attached an example on how this can be done. Copy the .txt file to "c:\Seagull" please.

     

    I've used an event based VBScript, where "OnNewRecord" event the following code is being used:

     

    myold = mynew
    mynew = Field("data.Ship To Address")
     
    if Strcomp (myold, mynew) <> 0 Then
        value = 0
    End If
     
    This way, you compare the old and the new "address", and if they turn out to be different then you reset the counter.
    0
  • Avatar
    Legacy Poster

    Thank you

    works very good

    One more thing I am looking for is to have a total of labels printed (per ship to address) on all labels

    Example:  KH497 13

    0
  • Avatar
    Domingo Rodriguez
    Moderator

    Unfortunately, it won't be possible to know beforehand how many labels you will print before the "Ship To" address changes, unless you open a second connection to the database by using VBScripting. 

    Would it perhaps be sufficient if you print the total number of labels at the end of each "Ship To" address?

    0
  • Avatar
    Legacy Poster

    No what I am looking to get x of y cases send so how can I get a  the y if the y is coming from the database and in my case the identical copies of label is set by data source from Qty

    Thank you

    0
  • Avatar
    Domingo Rodriguez
    Moderator

    Unfortunately, this is not possible as it would require BarTender to read data from more than one records while it is still processing the first record of the database. As mentioned, you would need to create a connection to your text database by using VBScript, and then read and sum the different quantities until the "Ship to Address Changes". The following VBScript code shows how you can open a text file in read mode by using VBScript. If the file doesn't exist, it will create it. Please note that this is just a very simple example which you will need to modify so that it is also capable of reading the Qty field:

     

    On error resume next
    Dim fs, file, fso, makedatafile, f
     
    If IsNumeric(Value) = False Then 
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.FileExists("c:\testfile.txt")
        if f = False then 
            Set makedatafile = fs.CreateTextFile("c:\testfile.txt", False)
              Set file = fs.OpenTextFile("c:\testfile.txt")  
            makedatafile.writeline "1"
        Else
              Set file = fs.OpenTextFile("c:\testfile.txt")  
             Value = file.ReadLine
        End If
        Value = file.ReadLine
    End if
    Value = Value
    0

Please sign in to leave a comment.