通过访问数据库使用For循环 [英] Using For Loop through an access Database

查看:398
本文介绍了通过访问数据库使用For循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人都好


使用For循环访问我的数据库中的记录但是代码打开而不是基于用户传递的值的特定记录。这些值是我想要制作密钥的数据库中的字段。


这个代码的一点点

Vb 6和微软访问


代码Vb:


如果rs.RecordCount = 0则退出Sub

rs.MoveFirst
For i = 1到rs.RecordCount''读取数据库中的所有记录

cbosch = rs(" CentNo")

Cand_No = rs(" IndexNo")

性别= rs(性别)

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")



''验证关键字段(Examseries,year,candNo和索引号。)

Exam_Sr = rs(" ExamSeries")

如果Exam_Sr =""然后

MsgBox(请输入正确的考试系列),vbOKOnly

ElseIf Exam_Sr = 1然后

frmListing.Exam_Series.Caption = 5月/ 6月

否则

Exam_Sr = 2

frmListing.Exam_Series.Caption =" Nov / Dec


Me.Exam_Sr.SetFocus

Me.Refresh

结束如果


Exam_Yr = rs( ExamYear)

如果Exam_Yr =""然后

MsgBox(请输入考试年份),vbOKOnly


Me.Exam_Yr.SetFocus

结束如果
在获取后将字段打印到另一个表单上

''显示名为frmListing的模态表单。

frmListing.Show vbModal ,我


rs.MoveNext

下一页我


代码结束

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了解你的代码,每件事都没问题,但我没有找到你的问题,或者我想念一些东西???


最好的问候
HI....

i understand your code and every thing is ok, but i didnt find your question, or i miss something???

Best Regards


感谢您的回复


问题是这个

for循环使用计数所有记录并打印数据库中的所有记录。


我不能做的就是能够选择使用候选人编号,考试年份和中心编号记录。


我不知道如何使用三个值作为搜索记录的关键。


感谢您的帮助。


新手
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


一种可能性是检查For循环中的这些字段,以决定是否处理记录。


一般来说,你可能想要使用 WHERE SQL中的子句用于确定哪些记录放在记录集中。你能告诉我们 rs 是如何创建的吗?
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循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆