1.引用MicroSoft Comm Control 6.0 '引用mscomm.ocx
2.在窗口中新建mscomm控件——MSComm0
Private Sub Form_Load() '窗体加载
On Error GoTo 错误:
initchk (MSComm0) '调用函数初始化COM端口
错误:
Select Case err
Case 3704 '连接已断开
DisplayMessage "网络已经中断,查明后再试! "
Case 3021 '没有新数据
DisplayMessage "客人资料未建立!请联系前台 "
Case -2147467259 '找不到数据源
DisplayMessage "网络没开通,检查前台电脑! "
Case 8002 '串口没有打开
DisplayMessage "读卡器COM5端口没有打开! "
Case Else
DisplayMessage "发生突发故障,查明后再试! "
End Select
DoCmd.Close acForm, "酒吧销售"
Resume 退出
End Sub
Public Function initchk(sc As Integer) As Boolean '读取串口的函数
On Error Resume Next
Private Sub MSComm0_OnComm() '串口的消息响应
On Error Resume Next
Me.刷卡.SetFocus
Select Case MSComm0.CommEvent '串口事件
Case comEvReceive '接收到数据
Dim Buffer As Variant