Do...Loop 循环
时 间:2010-04-06 16:52:05
作 者:杨鑫 ID:7434 城市:广州
摘 要:本文通过一些简单的ADO,来练习 Do...Loop 循环
正 文:
目的:练习 Do...Loop 循环
相关知识:ADO
语法:
Do [While | Until Condition]
[VBA statements]
[Exit Do]
[VBA statements]
Loop
或者,While(或 Until)也可以位于结构底部:
Do
[VBA statements]
[Exit Do]
[VBA statements]
Loop [While | Until Condition]
补充:当条件为 True 时, While 子句让 Do...Loop 中的VBA语句执行,否则,退出Do...Loop循环;
Until 子句的作用刚好相反,只有当条件为 False 时,Do...Loop中的代码才会执行。
代码:
Option Compare Database
Option Explicit
Public Sub PrintCompany()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "tblContacts", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
Do Until rs.EOF '设定循环条件:直到记录集的指针移动到空记录时,停止循环
Debug.Print rs![company] '打印公司名称
rs.MoveNext '移动到下一条记录
Loop '循环
rs.Close '关闭记录集
Set rs = Nothing '将记录集从内存中清除
End Sub
结果:
Nopa Auto Parts
Jiffy Auto Sales
All Start Autos
Columbia Chevy
James Auto Parts
Fillion Sales And Service
Tip Top Chevy
Newbury Auto
Peekskill Sales
KJ Auto Repair
R & G Monda Inc
Tires National
Hayes Auctions
Middletown Auto Parts
Bill Thomas Sales, Inc
Yantic Auto Parts
ACC Car Sales
A-1 Auto Sales
Main Street Used Auto Parts
LAN Trucking
ABC Trucking
Fordman Colonial Times
Circle Auto Sales
Sammy Fordman
Pine Plains BMY
Pleasantville Monda Inc
Newton Monda Inc
American Auto Sales
Allstate International Sales
Bush Sales
Fordman Sales
First Chance Auto
Nopa East Auto Parts
Last Stop Auto
McDonald Sales
On the Hill
El Pasco Auto Sales
SaundersTown Auto Sales
Hatter Sales
Corona Fordman Sales
Montclair Auto
Sherman Oaks Auto Sales
Bell Auto Sales
Jackpot Fordman
Jackhorn Monda, Inc
McHugh Cash Auto Sales
Sakes American Autos
Ghost Automobile Sales
Iron Springs Auto Sales
Salado Formal Auto Sales
Elsa Honest Sales
Chicota American Auto Sales
M&M Sales
Greenleaf Car Sales
Knox Sales
Jackson & Sons
Paul's Best Autos
Truxton Auto Sales
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access快速开发平台--对上传...(11.22)
- Access快速开发平台企业版--...(11.18)
- 不会用多表联合查询,多表查询没结果...(11.16)
- 【案例分享】主键字段值含有不间断空...(11.16)
- Access快速开发平台--后台D...(11.14)
- 微软Access邀测新Monaco...(11.12)
- Access列表框左右互选、列表框...(11.11)
- 高效率在导入数据前删除记录(11.10)
- Access报价单转订单示例代码(11.08)
- Access系统自带的日期选择器不...(11.08)