VB data控件问题 为什么我在实时采样完毕后 Recordset.AddNew不能再ACCESS数据库上添加新纪录
我的程序是这样的Dimab(3)AsByteDimavAsVariantDimwAsIntegerDimb1AsLongDimb2AsLongPrivateSubComm...
我的程序是这样的
Dim ab(3) As Byte
Dim av As Variant
Dim w As Integer
Dim b1 As Long
Dim b2 As Long
Private Sub Command11_Click()
Dim rcvnum() As Byte, rcvname() As Byte
Command11.Enabled = False
MSComm1.CommPort = 4 '端口设置为4
MSComm1.Settings = "9600,N,8,1"
MSComm1.InBufferSize = 30 '接收缓冲区为40字节
MSComm1.OutBufferSize = 2 '发送缓冲区为2字节
MSComm1.InputMode = comInputModeBinary '二进制接收
MSComm1.InputLen = 1 '一次从缓冲读取一个字节
MSComm1.SThreshold = 1 '一次从缓冲发送一个字节
MSComm1.InBufferCount = 0 '接收缓存清零
MSComm1.OutBufferCount = 0 '发送缓存清零
w = 0 '数据个数清零
MSComm1.RThreshold = 1 '接收一个字节产生一个OnComm事件
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
If Err Then
MsgBox "串口通信无效"
End If
End If
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
av = MSComm1.Input
ab(1) = av(0)
If ab(1) = &HFF Then
MSComm1.RThreshold = 0 '关闭MSComm1事件接收
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 2
w = w + 1
av = MSComm1.Input
ab(2) = av(0)
b1 = ab(2)
av = MSComm1.Input
ab(3) = av(0)
b2 = ab(3)
Select Case b1
Case &H1
Text3.Text = "地点1"
Case &H2
Text3.Text = "地点2"
Case &H3
Text3.Text = "地点3"
Case &H4
Text3.Text = "地点4"
End Select
Select Case b2
Case &H1
Text1.Text = "01"
Text2.Text = "张三"
Case &H2
Text1.Text = "02"
Text2.Text = "李四"
Case &H3
Text1.Text = "03"
Text2.Text = "王五"
Case &H4
Text1.Text = "04"
Text2.Text = "陈六"
End Select
Text4.Text = Time
Add_row
MSComm1.RThreshold = 1
End If
Case Else
End Select
End Sub
Private Sub Add_row() '这里调用的函数为什么添加不了
Data1.Recordset.AddNew
Data1.Recordset.Fields("编号") = Text1.Text
Data1.Recordset.Fields("姓名") = Text2.Text
Data1.Recordset.Fields("地点") = Text3.Text
' Data1.Recordset.Fields("时间") = Time
Data1.Recordset.Update
Data1.Refresh
End Sub
文本框是和数据库绑定的 为什么就不能添加类 展开
Dim ab(3) As Byte
Dim av As Variant
Dim w As Integer
Dim b1 As Long
Dim b2 As Long
Private Sub Command11_Click()
Dim rcvnum() As Byte, rcvname() As Byte
Command11.Enabled = False
MSComm1.CommPort = 4 '端口设置为4
MSComm1.Settings = "9600,N,8,1"
MSComm1.InBufferSize = 30 '接收缓冲区为40字节
MSComm1.OutBufferSize = 2 '发送缓冲区为2字节
MSComm1.InputMode = comInputModeBinary '二进制接收
MSComm1.InputLen = 1 '一次从缓冲读取一个字节
MSComm1.SThreshold = 1 '一次从缓冲发送一个字节
MSComm1.InBufferCount = 0 '接收缓存清零
MSComm1.OutBufferCount = 0 '发送缓存清零
w = 0 '数据个数清零
MSComm1.RThreshold = 1 '接收一个字节产生一个OnComm事件
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
If Err Then
MsgBox "串口通信无效"
End If
End If
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
av = MSComm1.Input
ab(1) = av(0)
If ab(1) = &HFF Then
MSComm1.RThreshold = 0 '关闭MSComm1事件接收
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 2
w = w + 1
av = MSComm1.Input
ab(2) = av(0)
b1 = ab(2)
av = MSComm1.Input
ab(3) = av(0)
b2 = ab(3)
Select Case b1
Case &H1
Text3.Text = "地点1"
Case &H2
Text3.Text = "地点2"
Case &H3
Text3.Text = "地点3"
Case &H4
Text3.Text = "地点4"
End Select
Select Case b2
Case &H1
Text1.Text = "01"
Text2.Text = "张三"
Case &H2
Text1.Text = "02"
Text2.Text = "李四"
Case &H3
Text1.Text = "03"
Text2.Text = "王五"
Case &H4
Text1.Text = "04"
Text2.Text = "陈六"
End Select
Text4.Text = Time
Add_row
MSComm1.RThreshold = 1
End If
Case Else
End Select
End Sub
Private Sub Add_row() '这里调用的函数为什么添加不了
Data1.Recordset.AddNew
Data1.Recordset.Fields("编号") = Text1.Text
Data1.Recordset.Fields("姓名") = Text2.Text
Data1.Recordset.Fields("地点") = Text3.Text
' Data1.Recordset.Fields("时间") = Time
Data1.Recordset.Update
Data1.Refresh
End Sub
文本框是和数据库绑定的 为什么就不能添加类 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询