Skip to main content

Search

Search

Find Next Empty Row In Excel And Populate With Data

Comments

3 comments

  • Avatar
    Canguita

    Hello Sam,

     

    Thank you very much for your post. In order to don't overwrite your records in Excel we have some VBscript events as OnNewRecord() or OnPostPrompt() where you will be able to edit your VBscript

     

     

    I've attached you a sample. In the BarTender label format I have made a connection to the Excel file, which assumes it will be found in the "C:\Seagull" folder.  It uses a query to only find and therefore possibly print those products (records) that do not have the word "YES" in the "Printed" column.  The select record at print time option is turned on allowing the user to select which of the records that have not been printed, are to be printed.
     
    During the print job the VB script contained in the object in red placed off the label, runs a section of code that connects to the Excel file, finds the record being printed and sets the "Printed" field to the value "YES" so that next time the user prints it will not be available in the select at print time dialog to choose.  The VB script is as follows.
     
    OnNewRecord event
     
    'Define the object names.
    dim objConn
    dim strConn
    dim rs
     
    'Define the database connection parameter constants.
    Const adOpenStatic = 3
    Const adLockOptimistic = 3
    Const adCmdText = &H0001
     
    'Connect to the Excel file.
    Set objConn = CreateObject("ADODB.Connection")
    objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Seagull\Fruits.xls';Extended Properties=""Excel 8.0;HDR=YES;"""
     
    'Create a record set of one record which is the current record being printed.
    Set rs = CreateObject("ADODB.Recordset")
    rs.open "SELECT * FROM [Sheet1$]", objConn, adOpenStatic, adLockOptimistic, adCmdText
    rs.Find "Product = '" & Field("Sheet1$.Product") & "'"
    'Set the "Printed" field of the record to be "YES" thus flagging it as having been printed.
    rs.Fields("Printed") = "YES"
    rs.Update
     
    Please let me know if this help you.
    0
  • Avatar
    Legacy Poster

    Carlos thanks for your reply. Our customer unfortunately wants to operate in a different mannor. They have issued us with a CSV file in MSDOS format containing the information to be printed on the label, hence is not a spreadsheet as such. We are then to update a seperate (new) spreadsheet with certain fields taken from Bartender which have been printed on the label. A method of tracking which records have been printed.

     

    The part where my knowledge fell down was to prompt excel to look at column A and input the data in the next available empty row with the VB script in Bartender.

    0
  • Avatar
    Canguita

    Hello Sam,

     

    Thank you very much for your feedback.

     

    Can you let me know why exactly do you need to write in your database?

     

    The problem here is that in VBscript when you access to a database you will work in a record, in this record you will be able to write on every database fields but you will not be able to write on a different record.

     

    Maybe with a very tedious workaround could be possible to write on a new record, however another problem is that if your code is writing in the next record on blank and your database connection is crossing the database until find empty records you will entry in a loop.

     

    Please let us know what your customer is requesting exactly and we will check if there is an easier alternative.

    0

Please sign in to leave a comment.