您的位置:程序门 -> vb -> 数据库(包含打印,安装,报表)



求教 关于vb中recordset.fileds问题 在线等。。。。。。。。。。。。。。。


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


求教 关于vb中recordset.fileds问题 在线等。。。。。。。。。。。。。。。[已结贴,结贴人:cq03600320]
发表于:2007-05-22 14:24:06 楼主
小弟在毕业设计中,用vb设计一管理系统
想在main.form的load过程中判断进入的用户是什么类别?如是管理员,则显示某一菜单,若是普通用户,则不显示那个菜单。
小弟的用户表有三个字段,分别是用户名、密码、用户类别,其中用户类别中只有两种值,一种是管理员,另种就是用户
现在就是想先判断用户类型是什么?然后据此执行是否显示某一菜单。


我代码如下:
private   sub   form_load()
menu_yhgl.visible   =   false
adodc1.recordsource   =   "用户表 "
adodc1.refresh
with   adodc1.recordset
if   .fields(2).value   =   "管理员 "   then   menu_yhgl.visible   =   true
end   with
end   sub

虽然没有报错,但是并没达到我预期效果。恳请各位达人多指点!
发表于:2007-05-22 14:42:281楼 得分:0
默认visible属性是什么?

if   .fields(2).value   =   "管理员 "   then  
        menu_yhgl.visible   =   true
else
        menu_yhgl.visible   =   false
end   if
发表于:2007-05-22 14:52:012楼 得分:0
默认是不显示的,你这样的做法我试过,是不行的
我估计是语法上有问题,思路还是比较清晰。
谢谢pzlk大侠的关注!
发表于:2007-05-22 16:11:533楼 得分:0
form_load的时候记录集还没打开,根本得不到用户名、密码
发表于:2007-05-22 16:14:424楼 得分:0
这个应该是在登陆窗体里判断的,而不是主窗体
在登陆窗体里判断后,相应的再在跳出的主窗体中visible掉一些功能
发表于:2007-05-22 16:18:565楼 得分:0
应该是在登陆窗口中判断,然后用一个公共变量传给主窗体
主窗体再作一些东东
发表于:2007-05-22 16:22:356楼 得分:0
各位大侠可否再详细点
我是个十足的菜鸟,也没系统学过vb,只是比葫芦画瓢
发表于:2007-05-22 16:28:327楼 得分:0
我现在改变想法了,想设计两个main页面
管理员用户进后是一个,而一般用户进来后是另一个

具体代码如下:提示错误为       实时错误3265   在对应所需名称或序数的集合中,未找到项目
private   sub   command1_click()
adodc1.recordsource   =   "   用户表   where   用户名= ' "   &   datacombo1.boundtext   &   " ' "
adodc1.refresh
if   datacombo1.boundtext   <>   " "   and   text1.text   <>   " "   and   text1.text   =   adodc1.recordset.fields( "密码 ")   and   adodc1.recordset.fields( "用户类型 ")   =   "管理员 "   then
main.show
unload   me
if   datacombo1.boundtext   <>   " "   and   text1.text   <>   " "   and   text1.text   =   adodc1.recordset.fields( "密码 ")   and   adodc1.recordset.fields( "用户类型 ")   =   "用户 "   then     //错误所处
main1.show
unload   me
else
if   tim   =   3   then
myval   =   msgbox( "密码输入错误已达3次,请想系统管理员查询! ",   0,   " ")
if   myval   =   vbok   then   end
end   if
if   datacombo1.boundtext   =   " "   then
msgbox   ( "请输入操作员! ")
datacombo1.setfocus
else
if   datacombo1.boundtext   <>   adodc1.recordset.fields( "用户名 ")   then
msgbox   ( "查无此操作员!,请重新输入操作员! ")
datacombo1.setfocus
else
if   text1.text   =   " "   then
msgbox   ( "请输入操作员密码! ")
text1.setfocus
else
if   text1.text   <>   adodc1.recordset.fields( "密码 ")   then
msgbox   ( "密码错误,请重新输入密码! ")
tim   =   tim   +   1
text1.setfocus
end   if
end   if
end   if
end   if
end   if
end   if
end   sub


请各位大侠多多指点,非常感谢!
发表于:2007-05-22 16:30:398楼 得分:5
global   变量名   as   string       '在模块中定义,用于保存登陆窗口中的用户类别
然后再主窗体中判断这个变量
发表于:2007-05-22 16:37:199楼 得分:0
你先不要做用户类别判断,看看能不能正常登陆进主窗体
发表于:2007-05-22 16:44:3510楼 得分:0
如果不做类别判断,那是可以进主窗体的
这个我以前就设计好的
发表于:2007-05-22 16:52:4811楼 得分:0

global   变量名   as   string       '在模块中定义,用于保存登陆窗口中的用户类别
然后再主窗体中判断这个变量

具体该怎么做啊?
实在搞不太明白
发表于:2007-05-22 16:52:5412楼 得分:0
正常登陆的代码贴出来
发表于:2007-05-22 16:57:5213楼 得分:15
我晕了

global   type   as   string                                                         '登陆窗体

adodc1.recordsource   =   "用户表 "
adodc1.refresh
type   =adodc1.recordset.fields(2).value  

private   sub   form_load()
if   type   =   "管理员 "   then                                         '主窗体
        menu_yhgl.visible   =   true
else
        menu_yhgl.visible   =   false
endif
endsub
发表于:2007-05-22 17:13:5214楼 得分:0
以下为正常登录代码,非常感谢shangshuobsj大侠的关注和帮助!

private   sub   command1_click()
adodc1.recordsource   =   "   用户表   where   用户名= ' "   &   datacombo1.boundtext   &   " ' "
adodc1.refresh
if   datacombo1.boundtext   <>   " "   and   text1.text   <>   " "   and   text1.text   =   adodc1.recordset.fields( "密码 ")   then
main.show
unload   me
else
if   tim   =   3   then
myval   =   msgbox( "密码输入错误已达3次,请想系统管理员查询! ",   0,   " ")
if   myval   =   vbok   then   end
end   if
if   datacombo1.boundtext   =   " "   then
msgbox   ( "请输入操作员! ")
datacombo1.setfocus
else
if   datacombo1.boundtext   <>   adodc1.recordset.fields( "用户名 ")   then
msgbox   ( "查无此操作员!,请重新输入操作员! ")
datacombo1.setfocus
else
if   text1.text   =   " "   then
msgbox   ( "请输入操作员密码! ")
text1.setfocus
else
if   text1.text   <>   adodc1.recordset.fields( "密码 ")   then
msgbox   ( "密码错误,请重新输入密码! ")
tim   =   tim   +   1
text1.setfocus
end   if
end   if
end   if
end   if
end   if
end   sub
发表于:2007-05-22 17:21:0715楼 得分:0
global   type   as   string       这句该往哪写啊?
老是弹出编译错误:常数、固定长度字符串、数组、用户定义类型以及declare语句不允许作为对象模块的public成员
发表于:2007-05-22 17:26:4916楼 得分:0
我qq号是157196741
欢迎加入即时探讨


快速检索

最新资讯
热门点击