请教一下!
运行后显示“rst电子词典.RecordCount=<对象变量或with块变量未设置>错误帮我看一下,下面代码哪边错了啊?
Option Explicit
Private conn As ADODB.Connection
Private rst电子词典 As ADODB.Recordset
Private SQLString As String
Private ConnString As String
'********************************************************************
'向数据库追加数据,实际操作时应先做重复性检查,确认没有重复记录后再追加记录
'********************************************************************
Private Sub cmdadd_Click()
With rst电子词典
.AddNew
!英文单词 = Me.Textywdc.Text
!词性 = Me.Textcixing.Text
!中文意思 = Me.Textzwys.Text
!例句 = Me.Textliju.Text
!翻译 = Me.Textfanyi.Text
.Update
.MoveLast
End With
End Sub
Private Sub cmdDelete_Click()
On Error Resume Next
rst电子词典.Delete
End Sub
Private Sub cmdExit_Click()
Unload Me
Form1.Show
End Sub
Private Sub cmdModify_Click()
On Error Resume Next
With rst电子词典
!英文单词 = Me.Textywdc.Text
!词性 = Me.Textcixing.Text
!中文意思 = Me.Textzwys.Text
!例句 = Me.Textliju.Text
!翻译 = Me.Textfanyi.Text
.Update
End With
End Sub
Private Sub DataGrid1_Click()
If rst电子词典.RecordCount > 0 Then
With rst电子词典
Me.Textywdc.Text = .Fields("英文单词")
Me.Textcixing.Text = .Fields("词性")
Me.Textzwys.Text = .Fields("中文意思")
Me.Textliju.Text = .Fields("例句")
Me.Textfanyi.Text = .Fields("翻译")
End With
End If
End Sub
Private Sub Form_Load()
Dim sFileName As String
sFileName = App.Path & "\Data\单词词库.mdb"
If Dir(sFileName) = "" Then
Exit Sub
End If
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sFileName & ";Persist Security Info=False"
SQLString = "Select * From 单词信息管理"
Set conn = New ADODB.Connection
Call conn.Open(ConnString)
Set rst电子词典 = New ADODB.Recordset
rst电子词典.CursorLocation = adUseClient
Call rst电子词典.Open(SQLString, conn, adOpenStatic, adLockOptimistic)
If rst电子词典.RecordCount > 0 Then
Set DataGrid1.DataSource = rst电子词典
With rst电子词典
.MoveFirst
Me.Textywdc.Text = .Fields("英文单词")
Me.Textcixing.Text = .Fields("词性")
Me.Textzwys.Text = .Fields("中文意思")
Me.Textliju.Text = .Fields("例句")
Me.Textfanyi.Text = .Fields("翻译")
End With
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo ErrorExit
Me.DataGrid1.Visible = False
Call rst电子词典.Close
Call conn.Close
Set rst电子词典 = Nothing
Set conn = Nothing
ErrorExit:
End Sub