เขียนโค้ดวนลูปอย่างไรค่ะ ตั้งแต่เร็คคอร์ดแรกถึงเร็คคอร์ดสุดท้าย
จะเขียนโค้ดให้วนลูป เพื่อแสดงข้อมูลจากdatabase ตั้งแต่เร็คคอร์แรกจนถึงเร็คคอร์ดสุดท้ายที่ตรงตามเงื่อนไข โดยแสดงออกมาจาก Msgbox เขียนยังไงมันก้แสดงแต่เร็คคอร์ดสุดท้ายเพียงเร็คคอร์ดเดียว ช่วยหน่อยนะคะ โค้ดก้มีประมาณนี้
Option Explicit Dim conn As New ADODB.Connection
Private Sub Cmd2_Click() Set conn = New ADODB.Connection 'Set txt = New ADODB.Command Dim rs As New ADODB.Recordset conn.ConnectionTimeout = 20 conn.CursorLocation = adUseServer conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\status_sts.mdb;Persist Security Info=False" conn.Open Dim sql Dim x As String Dim message, Tel, Type_Fault, Num As String Dim result1, result2, result3, result4 As String Dim result As String Dim i As Long Dim currentRecord 'Dim Text1 As Object Num = Len(Text1.Text) Type_Fault = Left(Text1.Text, 1) Tel = Mid(Num, 3, 11) If Num = "1" Then If Type_Fault = "F" Then sql = "select Tel ,desc_allarme from View_Fault_STS" ElseIf Type_Fault = "R" Then sql = "select Tel ,RevenueOnPas from View_Fault_STS" Else MsgBox "Êè§ãËÁè1" End If ElseIf Num = "11" Then If Type_Fault = "F" Then sql = "select Tel ,desc_allarme from View_Fault_STS where Tel ='" & Tel & "'" ElseIf Type_Fault = "R" Then sql = "select Tel ,RevenueOnPas from View_Fault_STS where Tel ='" & Tel & "'" Else MsgBox "Êè§ãËÁè2" End If Else MsgBox "¨Ó¹Ç¹µÑÇÍÑ¡ÉÃ" End If Set rs = conn.Execute(sql) If Type_Fault = "F" Then rs.MoveFirst Do While Not rs.EOF result1 = rs.Fields("Tel") result2 = rs.Fields("desc_allarme") rs.MoveNext result = result1 + result2 Loop ElseIf Type_Fault = "R" Then rs.MoveFirst Do While Not rs.EOF result1 = rs.Fields("Tel") result3 = rs.Fields("RevenueOnPas") result = result1 + result3 rs.MoveNext Loop Else MsgBox "¡ÃسÒÊè§¢éͤÇÒÁãËÁè" End If MsgBox (result) End Sub
แล้วพอกรอกข้อมูลไป 11 ตัว(Type_Fault=11) มันก้ขึ้น error : Either BOF or EOF is True, or the Current Record Has Been Deleted; the Operation Requested by the Application Requires a Current Record
ช่วยหน่อยนะคะ
|