Dim wr As Workspace '声明工作空间变量,为打开数据库提供空间 Dim db As Database '声明数据库对象变更,用于打开数据库 Dim dl As Recordset '声明数据库表,用于打开数据库库表 Dim DTYPE As String Dim DLOAD As String Dim DSPEED As String Dim DNBE As String Dim DNBS As String Dim DRMax As String Dim strSql As String Dim rs As Recordset Dim cou As Integer, i As Integer '以下使用DAO Set wr = CreateWorkspace("", "admin", "", dbUseJet) Set db = wr.OpenDatabase("C:\Program Files\Database.mdb", False, True, "") Set dl = db.OpenRecordset("Data", dbOpenDynaset, dbReadOnly) strSql = "select * from GVF-II where type='" & DTYPE & _ "' and load='" & DLOAD & "' and speed='" & DSPEED & _ "' and nbe='" & DNBE & "' and nbstopmax='" & DNBS & _ "' and rmax='" & DRMax & "'" Set rs = db.OpenRecordset(strSql, dbOpenDynaset) '如果根据此六个条件查得记录最多只有1条时,可使用以下代码 If rs.RecordCount > 0 Then Debug.Print rs.Fields("type") Debug.Print rs.Fields("load") Debug.Print rs.Fields("speed") Debug.Print rs.Fields("nbe") Debug.Print rs.Fields("nbstopmax") Debug.Print rs.Fields("rmax") '也可将值赋给控件,如:TextBox1.Text=rs.Fields("type") End If '如果根据此六个条件查得记录可能有2条以上时,可使用以下代码 If Not rs.EOF Then rs.MoveLast cou = rs.RecordCount rs.MoveFirst Else cou = rs.RecordCount rs.MoveFirst End If For i = 1 To cou Debug.Print rs.Fields("type") Debug.Print rs.Fields("load") Debug.Print rs.Fields("speed") Debug.Print rs.Fields("nbe") Debug.Print rs.Fields("nbstopmax") Debug.Print rs.Fields("rmax") rs.MoveNext Next i |