数据库(拷贝或移动列表框或组合框中的内容)

文章作者 100test 发表时间 2007:11:14 12:59:06
来源 100Test.Com百考试题网


在做数据库程序时,通常会要求用户将数据从一个列表框移动到别一个列表框中。下面的子程序可以让你轻松实现这一功能。同时还提供参数,指定操作是移动数据(不保留原数据),还是拷贝数据(保留数据的副本在原列表框或组合框中);并且还可以选择是全部移动或拷贝数据,还是只移动或拷贝用户选定的部分。

参数 值 说明
fromctl 源列表框或组合框名 源列表框或组合框
toctl 目的列表框或组合框名 目的列表框或组合框
strmode 可选参数,默认情况下只拷贝
选中的项目
- 移动选中的项目
all 拷贝所有的项目,不需选中
-all 移动所有的项目,不需选中

源程序如下:

public sub copycombolist(fromctl as control, toctl as control, optional
strmode as string)

on error resume next

dim intn as integer

screen.mousepointer = vbhourglass

if strmode <> "" then
strmode = ucase(strmode)
end if

with fromctl

if typename(fromctl) = "listbox" then
for intn = .listcount - 1 to 0 step -1
if .0selected(intn) or instr(strmode, "all") then
toctl.additem .list(intn)
toctl.itemdata(toctl.newindex) = .itemdata(intn)
if instr(strmode, "-") = 1 then
.removeitem (intn)
end if
next
else
for intn = .listcount - 1 to 0 step -1
toctl.additem .list(intn)
toctl.itemdata(toctl.newindex) = .itemdata(intn)
if instr(strmode, "-") = 1 then
.removeitem (intn)
next
end if
end with

screen.mousepointer = vbdefault

end sub

相关文章


VB辅导:VB的MsgBox函数
VB数据输入函数i utbox
FileLen函数和Filter函数
FormatPercent函数
数据库(拷贝或移动列表框或组合框中的内容)
如何在数据控件断开所有的数据连接
如何用VB访问外来数据库
VBfreefile()函数
VB中声明和使用API函数
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛