[求助]关于ado调用数据库问题
本帖最后由 作者 于 2005-7-7 20:34:59 编辑 <br /><br /> 在程序中我需要反复调用同一数据库中不同的表,代码如下,运行的时候提示需要运行对象。请大家帮我看看哪里错了,小女子万分感激!!!谢谢了!!!Private Sub UserForm_Initialize()<BR> <BR> strPath = "D:\sheji\" & "\" '连接数据库<BR> Set adoCon = New Connection<BR> adoCon.CursorLocation = adUseClient<BR> adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _<BR> strPath & "shujuku.mdb;"<BR> <BR> '打开记录集<BR> Set adoRs1 = New Recordset<BR> adoRs1.Open "gxgtweijia", adoCon, adOpenDynamic, adLockOptimistic<BR> <BR> <BR> RefreshList1 '将型号添加到列表框中<BR> <BR> If adoRs1.RecordCount > 0 Then<BR> adoRs1.MoveLast<BR> adoRs1.MoveFirst<BR> <BR> ExchangeData1 False<BR> End If<BR> <BR> <BR> <BR> Set adoRs2 = New Recordset<BR> adoRs2.Open "zhitui", adoCon, adOpenDynamic, adLockOptimistic<BR> <BR> RefreshList2 '将型号添加到列表框中<BR> <BR> If adoRs2.RecordCount > 0 Then<BR> adoRs2.MoveLast<BR> adoRs2.MoveFirst<BR> <BR> ExchangeData2 False<BR> End If<BR> <BR> <BR> <BR>End Sub
Private Sub RefreshList1()<BR> lstType1.Clear<BR> <BR> Dim i As Integer<BR> adoRs1.MoveFirst<BR> For i = 0 To adoRs1.RecordCount - 1<BR> lstType1.AddItem adoRs1.Fields("图号")<BR> If Not adoRs1.EOF Then<BR> adoRs1.MoveNext<BR> End If<BR> <BR> Next i<BR> <BR>End Sub<BR>Private Sub ExchangeData1(ByVal bSave As Boolean)<BR> If bSave Then<BR> adoRs1.Fields("H") = txt9.Text<BR> adoRs1.Fields("H1") = txt8.Text<BR> adoRs1.Fields("D") = txt7.Text<BR> <BR> <BR> Else<BR> <BR> txt9.Text = adoRs1.Fields("H")<BR> txt8.Text = adoRs1.Fields("H1")<BR> txt7.Text = adoRs1.Fields("D")<BR> <BR> End If<BR>End Sub
Private Sub lstType1_click()<BR> Dim i As Integer<BR> i = lstType1.ListIndex<BR> <BR> If i = -1 Then Exit Sub<BR> <BR> If i <= adoRs1.RecordCount - 1 Then<BR> adoRs1.MoveFirst<BR> adoRs1.Move i<BR> End If<BR> <BR> ExchangeData1 False<BR> <BR>End Sub
Private Sub RefreshList2()<BR> lstType2.Clear<BR> <BR> Dim i As Integer<BR> adoRs2.MoveFirst<BR> For i = 0 To adoRs1.RecordCount - 1<BR> lstType2.AddItem adoRs2.Fields("Ⅰ型图号")<BR> If Not adoRs2.EOF Then<BR> adoRs2.MoveNext<BR> End If<BR> <BR> Next i<BR> <BR>End Sub<BR>Private Sub ExchangeData2(ByVal bSave As Boolean)<BR> If bSave Then<BR> adoRs2.Fields("H1") = Text1.Text<BR> <BR> Else<BR> <BR> Text1.Text = adoRs2.Fields("H1")<BR> <BR> <BR> End If<BR>End Sub
Private Sub lstType2_click()<BR> Dim i As Integer<BR> i = lstType2.ListIndex<BR> <BR> If i = -1 Then Exit Sub<BR> <BR> If i <= adoRs2.RecordCount - 1 Then<BR> adoRs2.MoveFirst<BR> adoRs2.Move i<BR> End If<BR> <BR> ExchangeData2 False<BR> <BR>End Sub<BR>
把程序完整贴上来方便别人调试.
adoRs1.Open----adoRs1提示没有该属性 '打开记录集
Set adoRs1 = New ADODB.Recordset
adoRs1.Open "gxgtweijia", adoCon, adOpenDynamic, adLockOptimistic 楼上的~~俺按照你说的改了~~可还是提示"要求对象"
页:
[1]