急!VB操作Access问题!在线等!高分!

来源:百度知道 编辑:UC知道 时间:2024/07/02 03:41:49
Option Explicit

Dim rs As ADODB.Recordset
Dim strSQL As String
Dim msg As String
Dim Index As Integer
Dim flag As String '判断是新增记录还是修改记录
Private Sub Form_Load()
Call LoadData '装载数据
If rs.RecordCount > 0 Then
Call ShowData '显示数据
Else
For Index = 0 To 3
CmdMove(Index).Enabled = False
Next Index
End If
'控件可用性
CmdAdd.Enabled = True: CmdModify.Enabled = True: CmdDelete.Enabled = True
CmdCancel.Enabled = False: CmdSave.Enabled = False
End Sub
Private Sub ShowData()
'在文本框中显示数据
If rs.RecordCount <> 0 And rs.EOF = False Then
For Index = 8 To 28
If rs.Fields(Index) <> "" Then
txtItem(Index).Text = rs.Fields(Index)
Else
txtItem(Index).Text = ""
End If

写代码之前你需要引用ado 控件
具体的办法是添加部件的对话框中选中
microsoft Active Data ...Object control 这句不是很记得怎么写了。
Private Sub command1_click()
dim conn as new adodb.connection
dim rs as new adodb.recordset
dim str as string
dim sql as string
str = App.Path
If Right(str, 1) <> "\" Then
str = str + "\"
End If
str = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & str & "\Indicator.mdb"
conn.open str
rs.cursorlocation=aduseclient
sql="select * from Indicator order by Serial"
rs.open sql,conn,adopenkeyset.adlockpessimistic
上面是连接和打开数据库的代码.

看“我的消息”

我的消息