紧急求助!请大家一定帮忙解决一下,小弟先跪谢了!
以下是增加数据的代码,前面两个(热导率和比热容)在保存的时候都可以,代码基本上是一样的为什么后面的就不可以了,而且出现“没有为命令对象设置命令”的错误,但是如果把比热容这一段代码去掉,则密度相关的数据又可以保存了,不知道是怎么回事,请大家帮帮忙,很着急,谢谢了!
Private Sub Command1_Click()
Dim sql As String
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnection As String
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
strConnection = "provider=microsoft.jet.oledb.4.0;data source= " & App.Path & "\ThermalDBase.mdb " & ";Persist Security Info=False "
con.Open strConnection
If Trim(Me.DataCombo1) = " " Then
MsgBox "请选择合金牌号! ", vbOKOnly + vbExclamation, "系统提示 "
Me.DataCombo1.SetFocus
Exit Sub
End If
If Trim(Me.DataCombo2) = " " Then
MsgBox "请选择参数类型! ", vbOKOnly + vbExclamation, "系统提示 "
Me.DataCombo2.SetFocus
Exit Sub
End If
If DataCombo2.Text = "热导率 " Then
If Option1.Value = True Then
sql = "insert into rdl_bl (合金牌号,温度,修改状态,热导率,修改时间,备注) values ( ' " & DataCombo1 & " ', ' " & Text1 & " ', ' " & Combo1 & " ', ' " & Text2 & " ', ' " & DTPicker1.Value & " ', ' " & Text3 & " ') "
If Text1.Text = " " Then
MsgBox "请输入温度! ", vbOKOnly + vbExclamation, "系统提示 "
Text1.SetFocus
Exit Sub
End If
If Text2.Text = " " Then
MsgBox "请输入热导率! ", vbOKOnly + vbExclamation, "系统提示 "
Text2.SetFocus
Exit Sub
End If
If Combo1.Text = " " Then
MsgBox "请选择参数! ", vbOKOnly + vbExclamation, "系统提示 "
Combo1.SetFocus
Exit Sub
End If
ElseIf Option2.Value = True Then
sql = "insert into rdl_cs (合金牌号,修改状态,热导率,修改时间,备注) values ( ' " & DataCombo1 & " ', ' " & Combo2 & " ', ' " & Text4 & " ', ' " & DTPicker2.Value & " ', ' " & Text5 & " ') "
If Text4.Text = " " Then
MsgBox "请输入热导率! ", vbOKOnly + vbExclamation, "系统提示 "
Text4.SetFocus
Exit Sub
End If
If Combo2.Text = " " Then
MsgBox "请选择参数的目前状态! ", vbOKOnly + vbExclamation, "系统提示 "
Combo2.SetFocus
Exit Sub
End If
End If
End If
If DataCombo2.Text = "比热容 " Then
If Option1.Value = True Then
sql = "insert into brr_bl (合金牌号,温度,修改状态,比热容,修改时间,备注) values ( ' " & DataCombo1 & " ', ' " & Text6 & " ', ' " & Combo3 & " ', ' " & Text7 & " ', ' " & DTPicker3.Value & " ', ' " & Text8 & " ') "
If Text6.Text = " " Then
MsgBox "请输入温度! ", vbOKOnly + vbExclamation, "系统提示 "
Text6.SetFocus
Exit Sub
End If
If Text7.Text = " " Then
MsgBox "请输入比热容! ", vbOKOnly + vbExclamation, "系统提示 "
Text7.SetFocus
Exit Sub
End If
If Combo3.Text = " " Then
MsgBox "请选择参数的目前状态! ", vbOKOnly + vbExclamation, "系统提示 "
Combo3.SetFocus
Exit Sub
End If
ElseIf Option2.Value = True Then
sql = "insert into brr_cs (合金牌号,修改状态,比热容,修改时间,备注) values ( ' " & DataCombo1 & " ', ' " & Combo4 & " ', ' " & Text9 & " ', ' " & DTPicker4.Value & " ', ' " & Text10 & " ') "
If Text9.Text = " " Then
MsgBox "请输入比热容! ", vbOKOnly + vbExclamation, "系统提示 "
Text9.SetFocus
Exit Sub
End If
If Combo4.Text = " " Then
MsgBox "请选择参数的目前状态! ", vbOKOnly + vbExclamation, "系统提示 "
Combo4.SetFocus
Exit Sub
End If
End If
If DataCombo2.Text = "密度 " Then
If Option1.Value = True Then
sql = "insert into md_bl (合金牌号,温度,修改状态,密度,修改时间,备注) values ( ' " & DataCombo1 & " ', ' " & Text11 & " ', ' " & Combo5 & " ', ' " & Text12 & " ', ' " & DTPicker5.Value & " ', ' " & Text13 & " ') "
If Text11.Text = " " Then
MsgBox "请输入温度! ", vbOKOnly + vbExclamation, "系统提示 "
Text11.SetFocus
Exit Sub
End If
If Text12.Text = " " Then
MsgBox "请输入密度! ", vbOKOnly + vbExclamation, "系统提示 "
Text12.SetFocus
Exit Sub
End If
If Combo5.Text = " " Then
MsgBox "请选择参数的目前状态! ", vbOKOnly + vbExclamation, "系统提示 "
Combo5.SetFocus
Exit Sub
End If
ElseIf Option2.Value = True Then
sql = "insert into md_cs (合金牌号,修改状态,密度,修改时间,备注) values ( ' " & DataCombo1 & " ', ' " & Combo6 & " ', ' " & Text14 & " ', ' " & DTPicker6.Value & " ', ' " & Text15 & " ') "
If Text14.Text = " " Then
MsgBox "请输入密度! ", vbOKOnly + vbExclamation, "系统提示 "
Text14.SetFocus
Exit Sub
End If
If Combo6.Text = " " Then
MsgBox "请选择参数的目前状态! ", vbOKOnly + vbExclamation, "系统提示 "
Combo6.SetFocus
Exit Sub
End If
End If
End If
End If
con.Execute sql
MsgBox "记录已成功添加! ", vbOKOnly + vbExclamation, "系统提示! "
End Sub
[解决办法]
看不出来问题,你单步跟踪一下,看到哪句有问题?先帮顶
[解决办法]
错误原因:
con.Execute sql
此句执行时,若sql为空,则会提示如题的错误。
问题可能原因:DataCombo2.Text 中是否有相应的选项?option1,2是否选上了?
建议:在con.Execute sql前加上一个stop和debug.print sql 查看sql的值是多少,空的时候就找到错误了。
这样应该可以解决问题了。