Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Address Labels not working.

Status
Not open for further replies.

Fozzy9767

Technical User
Jun 12, 2006
58
US
I'm attempting to print data from a gridview to a Dymo Label Printer via Client-side Scripting. I'm getting an error on line 9: "Object doesn't support this property or method". I'm trying to pull the data into a string value to feed to the printer function. Here is my page code:
Code:
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head id="Head1" runat="server">
<script language=vbscript>
Sub Button1_onclick()
        Dim DymoAddIn, DymoLabel
        Dim strAddress 
        
        strAddress = DetailsView1.Rows(0).Cells(1).Text & vbCrLf & DetailsView1.Rows(1).Cells(1).Text & vbCrLf & DetailsView1.Rows(2).Cells(1).Text & ", " & DetailsView1.Rows(3).Cells(1).Text & DetailsView1.Rows(4).Cells(1).Text

        DymoAddIn = CreateObject("DYMO.DymoAddIn")
        DymoLabel = CreateObject("DYMO.DymoLabels")

        DymoAddIn.Open("C:\Program Files\Dymo Label\Label Files\Address (30252,30320).LWL")

        DymoLabel.SetAddress 1, strAddress
        DymoAddIn.Print 1, False


    End Sub
    </script>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <img src="images/TriS_logo_satisfaction_v2.jpg" />
        <img src="images/guarantee_v2_01.jpg" />
    </div>

    <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/CBLAPP.mdb"
        SelectCommand="SELECT [strMID], [strDBAName], [strDBAadd1], [strDBACity], [strDBAState], [strDBAZip] FROM [CBL_EOM_Data]">
    </asp:AccessDataSource>
    &nbsp; &nbsp;
    

    <table cols="2" style="width: 537px">
        <tr>
            <td style="width: 140px">
                <asp:Label ID="MID" runat="server" Text="Enter Merchant ID Number:" Width="181px"></asp:Label></td>
            <td style="width: 101px">
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="AccessDataSource1"
                    DataTextField="strMID" DataValueField="strMID" Width="171px">
                </asp:DropDownList></td>
        </tr>
        <tr>
            <td style="height: 67px;" colspan="2">
                <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="AccessDataSource2"
                    Height="50px" Width="510px">
                    <Fields>
                        <asp:BoundField DataField="strDBAName" HeaderText="Name" SortExpression="strDBAName" />
                        <asp:BoundField DataField="strDBAadd1" HeaderText="Address" SortExpression="strDBAadd1" />
                        <asp:BoundField DataField="strDBACity" HeaderText="City" SortExpression="strDBACity" />
                        <asp:BoundField DataField="strDBAState" HeaderText="State" SortExpression="strDBAState" />
                        <asp:BoundField DataField="strDBAZip" HeaderText="Zip" SortExpression="strDBAZip" />
                    </Fields>
                </asp:DetailsView>
                <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/CBLAPP.mdb"
                    SelectCommand="SELECT [strDBAName], [strDBAadd1], [strDBACity], [strDBAState], [strDBAZip] FROM [CBL_EOM_Data] WHERE ([strMID] = ?)">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="DropDownList1" Name="strMID" PropertyName="SelectedValue"
                            Type="String" />
                    </SelectParameters>
                </asp:AccessDataSource>
            </td>
        </tr>
        <tr><td style="text-align: center" colspan="2">
            <Input type=Button Name="Button1" onclick="Button1_onclick()" Value="Print Label" /></td></tr>
     </table>
   
</form>
   
</body>
</html>
 
OK, I switched to a JavaScript version and it will print a hard coded address. I need to have it pull the values displyed on the page at the time the button is clicked. I need to get the results from the DetailsView into the DymoLabel.SetAddress part of the script as a string, with appropriate carriage returns and punctuation. Here is my revised code:
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="PrintLabel.aspx.vb" Inherits="PrintLabel" title="Print Merchant Labels" %>
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head id="Head1" runat="server">
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <img src="images/TriS_logo_satisfaction_v2.jpg" />
        <img src="images/guarantee_v2_01.jpg" />
    </div>

    <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/CBLAPP.mdb"
        SelectCommand="SELECT [strMID], [strDBAName], [strDBAadd1], [strDBACity], [strDBAState], [strDBAZip] FROM [CBL_EOM_Data]">
    </asp:AccessDataSource>
    &nbsp; &nbsp;
    

    <table cols="2" style="width: 537px">
        <tr>
            <td style="width: 140px">
                <asp:Label ID="MID" runat="server" Text="Choose Merchant ID Number:" Width="181px"></asp:Label></td>
            <td style="width: 101px">
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="AccessDataSource1"
                    DataTextField="strMID" DataValueField="strMID" Width="171px">
                </asp:DropDownList></td>
        </tr>
        <tr>
            <td style="height: 67px;" colspan="2">
                <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="AccessDataSource2"
                    Height="50px" Width="510px">
                    <Fields>
                        <asp:BoundField DataField="strDBAName" HeaderText="Name" SortExpression="strDBAName" />
                        <asp:BoundField DataField="strDBAadd1" HeaderText="Address" SortExpression="strDBAadd1" />
                        <asp:BoundField DataField="strDBACity" HeaderText="City" SortExpression="strDBACity" />
                        <asp:BoundField DataField="strDBAState" HeaderText="State" SortExpression="strDBAState" />
                        <asp:BoundField DataField="strDBAZip" HeaderText="Zip" SortExpression="strDBAZip" />
                    </Fields>
                </asp:DetailsView>
                <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/CBLAPP.mdb"
                    SelectCommand="SELECT [strDBAName], [strDBAadd1], [strDBACity], [strDBAState], [strDBAZip] FROM [CBL_EOM_Data] WHERE ([strMID] = ?)">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="DropDownList1" Name="strMID" PropertyName="SelectedValue"
                            Type="String" />
                    </SelectParameters>
                </asp:AccessDataSource>
            </td>
        </tr>
        <tr><td style="text-align: center" colspan="2">
        <Input type=Button Name="Button1" onclick="Button1_OnClick()" Value="Print Label" />
            </td></tr>
     </table>
   
</form>
   <SCRIPT>
      function Button1_OnClick()
      {
        var DymoAddIn, DymoLabel;
        DymoAddIn = new ActiveXObject('DYMO.DymoAddIn');
        DymoLabel = new ActiveXObject('DYMO.DymoLabels');

        if (DymoAddIn.Open('C:\\Documents and Settings\\All Users\\Documents\\DYMO Label\\Label Files\\Address (30252, 30320, 30572).LWL'))
        {
          DymoLabel.SetAddress(1, 'Pablo Martini1\nSAMPLE Corporation\n333 W. Fantasy World\nSantaland, NP 99999-9999');
          DymoAddIn.Print(1, true);

	  // this is how to print to the "Right Roll" of a TwinTurbo
	  //DymoAddIn.StartPrintJob();
	  //DymoAddIn.Print2(1, false, 1); // 0 = left roll, 1 = right roll, 2 = auto-switch
	  //DymoAddIn.EndPrintJob();
        }
        else if (DymoAddIn.Open('C:\\Program Files\\DYMO Label\\Label Files\\Address (30252, 30320, 30572).LWL'))
        {
          DymoLabel.SetAddress(1, 'Pablo Martini1\nSAMPLE Corporation\n333 W. Fantasy World\nSantaland, NP 99999-9999');
          DymoAddIn.Print(1, true);

	  // this is how to print to the "Right Roll" of a TwinTurbo
	  //DymoAddIn.StartPrintJob();
	  //DymoAddIn.Print2(1, false, 1); // 0 = left roll, 1 = right roll, 2 = auto-switch
	  //DymoAddIn.EndPrintJob();
        }
        else if (DymoAddIn.Open('C:\\Program Files\\Dymo Label\\Label Files\\Address  (30252, 30320).LWT'))
        {
          DymoLabel.SetAddress(1, 'Pablo Martini2\nSAMPLE Corporation\n333 W. Fantasy World\nSantaland, NP 99999-9999');
          DymoAddIn.Print(1, true);

	  // this is how to print to the "Right Roll" of a TwinTurbo
	  //DymoAddIn.StartPrintJob();
	  //DymoAddIn.Print2(1, false, 1); // 0 = left roll, 1 = right roll, 2 = auto-switch
	  //DymoAddIn.EndPrintJob();
        }
        else
          alert('Error: Label file Not Found!');
       }
     </SCRIPT>

</body>
</html>
 
In your fields collection, make a ButtonField or a TemplateField that creates a "Print" button, passing all the values you need to the OnClick event to do the print.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top