概述
Hello everyone
Am using a For Loop to access records from my database but the code opens instead of a specific record base on values passed by the user. These values a fields in the database which i want to make keys.
This a bit of the code
Vb 6 and Microsof Access
code Vb:
If rs.RecordCount = 0 Then Exit Sub
rs.MoveFirst
For i = 1 To rs.RecordCount '' Read all the records from database
cbosch = rs("CentNo")
Cand_No = rs("IndexNo")
Sex = rs("Sex")
DOB = rs("DOB")
Cnd_Name = rs("CandName")
Grd11 = rs("Grd1")
Subj2 = rs("Subj2")
Grd12 = rs("Grd2")
Subj3 = rs("Subj3")
Grd13 = rs("Grd3")
Subj4 = rs("Subj4")
Grd14 = rs("Grd4")
Subj5 = rs("Subj5")
Grd15 = rs("Grd5")
Subj6 = rs("Subj6")
Grd16 = rs("Grd6")
Subj7 = rs("Subj7")
Grd17 = rs("Grd7")
Subj8 = rs("Subj8")
Grd18 = rs("Grd8")
''validate the Key fields (Examseries, year, candNo and index no.)
Exam_Sr = rs("ExamSeries")
If Exam_Sr = "" Then
MsgBox ("Pls enter the correct Exam Serie"), vbOKOnly
ElseIf Exam_Sr = 1 Then
frmListing.Exam_Series.Caption = "May/June"
Else
Exam_Sr = 2
frmListing.Exam_Series.Caption = "Nov/Dec"
Me.Exam_Sr.SetFocus
Me.Refresh
End If
Exam_Yr = rs("ExamYear")
If Exam_Yr = "" Then
MsgBox ("Please Enter the exam year"), vbOKOnly
Me.Exam_Yr.SetFocus
End If
It prints the fields on to another form after getting them
''Show a modal form named frmListing.
frmListing.Show vbModal, Me
rs.MoveNext
Next i
code ends
解决方案HI....
i understand your code and every thing is ok, but i didnt find your question, or i miss something???
Best Regards
Thanks for the reply
The problem is this
the for loop am using counts all the records and the prints all of the records from the database.
What i can''t do is to be able to choose record by record using the the Candidate No, Year of exam and centre No.
I just don''t how to use these three values as a key to search for a record.
Thanks for your help.
Newbie
One possibility would be to check these fields inside the For loop, to decide whether to process the record.
Generally though, you would probably want to use a WHERE clause in your SQL to determine which records are placed in the recordset. Can you show us how rs was created?
最后
以上就是耍酷水池为你收集整理的for循环里面连接mysql,通过访问数据库使用For循环的全部内容,希望文章能够帮你解决for循环里面连接mysql,通过访问数据库使用For循环所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复