Public CSapp As LabelManager2.Application
Public CSdoc As LabelManager2.Document
Public CSvars As LabelManager2.Variables
Dim label_dt As DataTable
Public Function ServerStart() As Boolean 'lab_object建立及error检测
Dim LastErr&
'On Error Resume Next ' catch errors
CSapp = New LabelManager2.Application 'implements object
'Set MYDOC = MyApp.ActiveDocument
LastErr = Err.Erl ' store resulting error code
On Error GoTo 0 ' returns to normal error trapping
Select Case LastErr ' depending on error code...
Case 0 ' no error, return true
ServerStart = True
Case 429 ' OLE common error, display special message
MsgBox("Cannot find or start OLE server, please check its registration.", vbCritical)
Case Else ' for other errors, use VB error processing
Err.Raise(LastErr)
End Select
End Function
Public Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
MessageBox.Show("无法释放 " & o & " 物件")
Finally
o = Nothing
End Try
End Sub
Private Sub CS_Print_Label(ByVal label_path As String)
If ServerStart() = True Then
CSdoc = CSapp.Documents.Open(label_path, False) 'lable档的object
CSvars = CSdoc.Variables
If CSvars Is Nothing Then
MessageBox.Show("CS Lalel doesn't exsit")
Exit Sub
End If
Dim Other_str, Lan_Model As String
Other_str = Me.TextBox_Other.Text.ToString.ToUpper
Lan_Model = Me.ComboBox1.Text.ToString
‘这里是给Dt赋值,动态调用数据库数据
Sql = "Select * Form tabel_name"
label_dt = Run_SQL(Sql).Tables(0)
If label_dt.Rows.Count = 0 Then
Info_Msg_Box("数据不存,不能打印!")
Return
End If