设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 3815|回复: 10
打印 上一主题 下一主题

[Access本身] 求遍历并提取数据的代码(已解决)

[复制链接]
1#
发表于 2011-4-8 09:28:22 | 显示全部楼层
与代码无关,不过是查询问题而已。
select iif(数据1>0,数据1) as 值1, iif(数据2>0,数据2) as 值2,iif(数据3>0,数据3) as 值3  from tbname
2#
发表于 2011-4-8 11:07:23 | 显示全部楼层
GAOZHONG 发表于 2011-4-8 11:04
不是我要的排列,我可能没表达清楚,我要实现如下效果:
数据1      数据2       数据3
  12           1 ...


http://www.office-cn.net/thread-96591-1-1.html
3#
发表于 2011-4-8 11:17:29 | 显示全部楼层
GAOZHONG 发表于 2011-4-8 11:10
我的目的可以查看
请帮忙解决子报表数据排列的问题,急!
http://www.office-cn.net/forum-viewthread-ti ...

你什么都不会呀,呵呵。

1、写一个自定义函数:
function valUpdate()
dim rs as new adodb.recordset
dim rs0 as new adodb.recordset
dim i as long,j as long
rs.Open "你的数据表名称", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rs0.Open "你的临时数据表名称", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
if rs0.recordcount>0 then
   for i=1 to rs0.recordcount
       rs0.delect
       rs0.update
   next
end if
for i=1 to rs.recordcount
      fro j=0 to rs.fileds.count-1
           if rs.filds(j).name="数据1" or rs.filds(j).name="数据2" or rs.filds(j).name="数据3"  then
                if nz(rs.filds(j).value,0)<>0 then
                      rs0.addnew
                      rs0("临时表中的字段名称").value=rs.filds(j).value
                      rs0.update
                end if
          end if
     next
    rs.movenext
next
rs.close:set rs=noting
rs0.close:set rs0=nothing
end function

2、在某个按钮事件中调用该函数:
call valUpdate
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-9 09:42 , Processed in 0.132054 second(s), 25 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表