我正在使用“OPOS”打印机和 Access 2007,并且试图让一些访问 VBA 代码与驱动程序交互。
到目前为止,我得到了这个 VBA6 程序,我正在尝试使用 Access VBA:
表格1.frm:
VERSION 5.00
Object = "{CCB90150-B81E-11D2-AB74-0040054C3719}#1.0#0"; "OPOSPOSPrinter.ocx"
Begin VB.Form Step1
BorderStyle = 1 'fixed
Caption = "Step1: ""Hello OPOS"" is printed "
ClientHeight = 1590
ClientLeft = 45
ClientTop = 330
ClientWidth = 3795
LinkTopic = "MDIForm1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1590
ScaleWidth = 3795
StartUpPosition = 3 'Windows default value
Begin VB.CommandButton cmdPrint
Caption = "Print Now"
Height = 450
Left = 1155
TabIndex = 0
Top = 525
Width = 1515
End
Begin OposPOSPrinter_CCOCtl.OPOSPOSPrinter OPOSPOSPrinter1
Left = 3120
OleObjectBlob = "Step1.frx":0000
Top = 960
End
End
Attribute VB_Name = "Step1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Step 1: "Hello OPOS" gets printed
Option Explicit
Private Sub cmdPrint_Click()
'send a string to the printer using method PrintNormal
'vbCrLf is VisualBasic standard newline
OPOSPOSPrinter1.PrintNormal PTR_S_RECEIPT, "Hello OPOS" + vbCrLf
End Sub
Private Sub Form_Load()
With OPOSPOSPrinter1
'open device
.Open "Unit1"
'Claim exclusive access
.ClaimDevice 1000
'enable the device
.DeviceEnabled = True
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
With OPOSPOSPrinter1
'stop device
.DeviceEnabled = False
'Release exclusive access
.ReleaseDevice
'Done with the printer
.Close
End With
End Sub
还
包含此其他文件:OposAll.bas
...可以在 VBA 项目文件中看到:
Type=Exe
Form=Step1.frm
Module=OPOS; ..\..\..\..\Include\OposAll.bas
Object={CCB90150-B81E-11D2-AB74-0040054C3719}#1.0#0; OPOSPOSPrinter.ocx
IconForm="Step1"
Startup="Step1"
HelpFile=""
Title="SamplePrint1"
Command32=""
Name="SamplePrint1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="MECS"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1
我很难弄清楚如何将其转换为有效的 Access VBA 代码。
我的问题可能看起来很愚蠢,但请记住,我既不知道 VBA6 也不知道 Access 2007 VBA。但是使用 DLL 版本相当容易,我认为这也是可行的。
1)愚蠢的问题:这段代码代表什么?它是在初始化某个对象吗?Access 似乎不喜欢该OPOSPOSPrinter1
部分,是否有另一种方法可以在 Access 中完成此操作?
Begin OposPOSPrinter_CCOCtl.OPOSPOSPrinter OPOSPOSPrinter1
Left = 3120
OleObjectBlob = "Step1.frx":0000
Top = 960
End
2)这可能是最重要的问题:是否有更明智的方式与 Access 2007 VBA 中的 OCX 驱动程序进行通信?