CommonDialog1.ShowPrinter我用了一个ShowPrinter方法调出一个打印对话框,对话框有两个按钮,一个是“打印”,一个是“取消”,无论我点哪一个,都会打印。我想知道怎么让他点“取消”的时候不打印。
解决方案 »
- 再次提问:已知菜单的名字,如何调动菜单的事件???
- 看看有什么错误?谢谢
- 在vb中可以不连接数据库直接把两个excel表中的字段通过某个字段连接起来吗?
- 关于控件属性页的问题,急,请帮忙看看(实在没分了)
- crystal 9.0 無法動態添加數據庫連接???請9.0的高手幫助
- 有没有生成pdf文件的控件?
- 请问如何用VB调用Excel
- 哪个API可以改系统窗体标题栏的颜色?
- IOBJECTCONSTRUCT什么意思,我看了MSDN。无奈英文差
- 请问,我自己建立了一个DLL,我如何在其它程序中调用这个DLL呢?
- 类似窗体的收缩和伸展问题...
- VB运行的时候.0x7c9516指令引用0x00000031,该内存不能为buy wooden windows read"内存的有时是不能writen这样的对话框总弹出.
dialog1.CancelError =true
On Error GoTo Cancel
...
Cancel:
printer.killdoc
' 设置“取消”为 True
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
' 显示“打印”对话框
CommonDialog1.ShowPrinter
'写需执行的打印代码
MsgBox "START"
Exit Sub
ErrHandler:
' 用户按了“取消”按钮
MsgBox "STOP"
Exit Sub
End Sub
On Error GoTo Err
CommonDialog1.CancelError = True
CommonDialog1.ShowPrinter
Err:
If Err.Number = 32755 Then
MsgBox "你按了取消!", vbCritical, "系统提示"
End If
End SubCancelError 属性返回或设置一个值,该值指示当选取“取消”按钮时是否出错。当该属性设置为 True 时,无论何时选取“取消”按钮,均产生 32755 (cdlCancel) 号错误。你可以利用On Error捕捉它。
另外,如果用户在“打开”、“另存为”对话框中选择“取消”按钮,Filename属性得到的是空串
On Error GoTo Cancel
If Dir("printdb.mdb") = "" Then '判断当前路径方法
Set s = DAO.Workspaces(0).CreateDatabase(App.Path + "/printdb.mdb", dbLangGeneral)
's.NewPassword "", "1" '设置数据库密码为1
str_SQL1 = "Create Table 计量单(日期 Date,编号 long ,收货单位 text(50), 销售订单号 text(50) ,生产订单号 text(50) ,产品名称 text(50) ,卡号 text(50) ,钢号 text(50) ,等级 text(50) ,箱号 text(50),规格 text(50) ,表面 text(50) ,产品标准 text(100) ,计量毛重 text(50) ,计量皮重 text(50) ,计量净重 text(50) ,质量扣重 text(50) ,包装扣重 text(50) ,交货重量 text(50))" 'Single,,,,,,,,,,,,,,, ,,
s.Execute str_SQL1
str_SQL2 = "Create Table 标签(牌号 text(50),规格 text(50),标准 text(50),C100厚度 text(50),卷(箱)号 text(50),表面加工 text(50),卡片号 text(50),等级 text(50),毛重 single,边部 text(50),净重 single,日期 Date ,检查员 text(10))" '
s.Execute str_SQL2Else
Set mydatabase = New ADODB.Connection
Set myrecordset1 = New ADODB.Recordset
mydatabase.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\printdb.mdb;Persist Security Info=False"
mydatabase.OpenSql = "Select * from 计量单"Set myrecordset1.ActiveConnection = mydatabase
myrecordset1.CursorLocation = adUseClient
myrecordset1.Source = Sql
myrecordset1.CacheSize = 30
myrecordset1.Open , mydatabase, adOpenKeyset, adLockOptimistic, adCmdText
myrecordset1.AddNewmyrecordset1("日期") = Date
myrecordset1("收货单位") = Text12.Text
myrecordset1("销售订单号") = Text9.Text
myrecordset1("生产订单号") = Text4.Text
myrecordset1("产品名称") = Text7.Text
myrecordset1("卡号") = Text2.Text
myrecordset1("钢号") = Comboganghao.Text
myrecordset1("等级") = Combodengji.Text
myrecordset1("箱号") = Text3.Text
myrecordset1("规格") = Text1.Text & Text6.Text
myrecordset1("表面") = Combobiaomian.Text
myrecordset1("产品标准") = Combobiaozhun.Text
myrecordset1("计量毛重") = Text10.Text
myrecordset1("计量皮重") = Text13.Text
myrecordset1("计量净重") = Text15.Text
myrecordset1("质量扣重") = Text11.Text
myrecordset1("包装扣重") = Text14.Text
myrecordset1("交货重量") = Text16.Textmyrecordset1.Update
myrecordset1.Close
End IfCommonDialog1.ShowPrinterPrinter.FontSize = 20
Printer.Print
Printer.FontSize = 14
Printer.CurrentX = 1600
Printer.Print Combobiaozhun.Text;
Printer.CurrentX = 4772 + 3170
Printer.Print Text8.Text
。省略了Printer.EndDoc '把这一句加上
Cancel:
Printer.KillDoc Exit Sub
End Sub
On Error GoTo Cancel
CommonDialog1.ShowPrinter
Printer.FontSize = 20
Printer.Print
Printer.FontSize = 14
Printer.CurrentX = 1600
Printer.Print Combobiaozhun.Text;
Printer.CurrentX = 4772 + 3170
Printer.Print Text8.Text
'????省略了
Printer.EndDoc '把这一句加上
Call sub_SaveData
Exit Sub
Cancel:
Printer.KillDoc Exit Sub
End SubPrivate Sub sub_SaveData()
If Dir("printdb.mdb") = "" Then '判断当前路径方法
Set s = DAO.Workspaces(0).CreateDatabase(App.Path + "/printdb.mdb", dbLangGeneral)
's.NewPassword "", "1" '设置数据库密码为1
str_SQL1 = "Create Table 计量单(日期 Date,编号 long ,收货单位 text(50), 销售订单号 text(50) ,生产订单号 text(50) ,产品名称 text(50) ,卡号 text(50) ,钢号 text(50) ,等级 text(50) ,箱号 text(50),规格 text(50) ,表面 text(50) ,产品标准 text(100) ,计量毛重 text(50) ,计量皮重 text(50) ,计量净重 text(50) ,质量扣重 text(50) ,包装扣重 text(50) ,交货重量 text(50))" 'Single,,,,,,,,,,,,,,, ,,
s.Execute str_SQL1
str_SQL2 = "Create Table 标签(牌号 text(50),规格 text(50),标准 text(50),C100厚度 text(50),卷(箱)号 text(50),表面加工 text(50),卡片号 text(50),等级 text(50),毛重 single,边部 text(50),净重 single,日期 Date ,检查员 text(10))" '
s.Execute str_SQL2
Else
Set mydatabase = New ADODB.Connection
Set myrecordset1 = New ADODB.Recordset
mydatabase.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\printdb.mdb;Persist Security Info=False"
mydatabase.Open
Sql = "Select * from 计量单"
Set myrecordset1.ActiveConnection = mydatabase
myrecordset1.CursorLocation = adUseClient
myrecordset1.Source = Sql
myrecordset1.CacheSize = 30
myrecordset1.Open , mydatabase, adOpenKeyset, adLockOptimistic, adCmdText
myrecordset1.AddNew
myrecordset1("日期") = Date
myrecordset1("收货单位") = Text12.Text
myrecordset1("销售订单号") = Text9.Text
myrecordset1("生产订单号") = Text4.Text
myrecordset1("产品名称") = Text7.Text
myrecordset1("卡号") = Text2.Text
myrecordset1("钢号") = Comboganghao.Text
myrecordset1("等级") = Combodengji.Text
myrecordset1("箱号") = Text3.Text
myrecordset1("规格") = Text1.Text & Text6.Text
myrecordset1("表面") = Combobiaomian.Text
myrecordset1("产品标准") = Combobiaozhun.Text
myrecordset1("计量毛重") = Text10.Text
myrecordset1("计量皮重") = Text13.Text
myrecordset1("计量净重") = Text15.Text
myrecordset1("质量扣重") = Text11.Text
myrecordset1("包装扣重") = Text14.Text
myrecordset1("交货重量") = Text16.Text
myrecordset1.Update
myrecordset1.Close
End IfEnd Sub
On Error GoTo Cancel
CommonDialog1.ShowPrinter
Printer.FontSize = 20
Printer.Print
Printer.FontSize = 14
Printer.CurrentX = 1600
Printer.Print Combobiaozhun.Text;
Printer.CurrentX = 4772 + 3170
Printer.Print Text8.Text
'????省略了
Printer.EndDoc '把这一句加上
Call sub_SaveData
Exit Sub
Cancel:
Printer.KillDoc Exit Sub
End SubPrivate Sub sub_SaveData()
If Dir("printdb.mdb") = "" Then '判断当前路径方法
Set s = DAO.Workspaces(0).CreateDatabase(App.Path + "/printdb.mdb", dbLangGeneral)
's.NewPassword "", "1" '设置数据库密码为1
str_SQL1 = "Create Table 计量单(日期 Date,编号 long ,收货单位 text(50), 销售订单号 text(50) ,生产订单号 text(50) ,产品名称 text(50) ,卡号 text(50) ,钢号 text(50) ,等级 text(50) ,箱号 text(50),规格 text(50) ,表面 text(50) ,产品标准 text(100) ,计量毛重 text(50) ,计量皮重 text(50) ,计量净重 text(50) ,质量扣重 text(50) ,包装扣重 text(50) ,交货重量 text(50))" 'Single,,,,,,,,,,,,,,, ,,
s.Execute str_SQL1
str_SQL2 = "Create Table 标签(牌号 text(50),规格 text(50),标准 text(50),C100厚度 text(50),卷(箱)号 text(50),表面加工 text(50),卡片号 text(50),等级 text(50),毛重 single,边部 text(50),净重 single,日期 Date ,检查员 text(10))" '
s.Execute str_SQL2
Else
Set mydatabase = New ADODB.Connection
Set myrecordset1 = New ADODB.Recordset
mydatabase.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\printdb.mdb;Persist Security Info=False"
mydatabase.Open
Sql = "Select * from 计量单"
Set myrecordset1.ActiveConnection = mydatabase
myrecordset1.CursorLocation = adUseClient
myrecordset1.Source = Sql
myrecordset1.CacheSize = 30
myrecordset1.Open , mydatabase, adOpenKeyset, adLockOptimistic, adCmdText
myrecordset1.AddNew
myrecordset1("日期") = Date
myrecordset1("收货单位") = Text12.Text
myrecordset1("销售订单号") = Text9.Text
myrecordset1("生产订单号") = Text4.Text
myrecordset1("产品名称") = Text7.Text
myrecordset1("卡号") = Text2.Text
myrecordset1("钢号") = Comboganghao.Text
myrecordset1("等级") = Combodengji.Text
myrecordset1("箱号") = Text3.Text
myrecordset1("规格") = Text1.Text & Text6.Text
myrecordset1("表面") = Combobiaomian.Text
myrecordset1("产品标准") = Combobiaozhun.Text
myrecordset1("计量毛重") = Text10.Text
myrecordset1("计量皮重") = Text13.Text
myrecordset1("计量净重") = Text15.Text
myrecordset1("质量扣重") = Text11.Text
myrecordset1("包装扣重") = Text14.Text
myrecordset1("交货重量") = Text16.Text
myrecordset1.Update
myrecordset1.Close
End IfEnd Sub