帮我看看代码错在哪里,怎么会提示对象变量或with变量未设置,谢谢了
我想添加记录到access数据库,但程序运行时总提示对象变量块或with变量未设置,帮我看看代码哪里有问题,麻烦各位了。
Option Explicit
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Dim r As Integer
Dim Dmin As Integer
Private Sub Command1_Click()
Dim Dmin As Integer
rs.Open "select max(id) as [dmin] from 航线动态表", db, adOpenKeyset, adLockOptimistic
Dmin = Val(rs(0).Value)
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("id") = Dmin + 1
Adodc1.Recordset.Fields("日期") = date1.Value
Adodc1.Recordset.Fields("航线名称") = Combo1.Text
Adodc1.Recordset.Fields("内容") = Text2.Text
Adodc1.Recordset.Fields("标题") = Text1.Text
Adodc1.Recordset.Update
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.MoveLast
Adodc1.Refresh
End Sub
Private Sub Form_Load()
Text1.Text = ""
date1.Value = Date
Combo1.Text = ""
Text2.Text = ""
Dim strsql2 As String, i As Integer
strsql2 = "select * from [航线表] order by id"
Set rs = queryext4(strsql2)
i = 0
With Combo1
Do While Not rs.EOF
.AddItem rs("航线名称")
.ItemData(i) = rs("id")
rs.MoveNext
i = i + 1
Loop
End With
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\vb2010.mdb;Persist Security Info=False;"
Adodc1.Recordset.MoveLast
End Sub
[解决办法]
我也不知道,不好意思