Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2336|回复: 9

[已解决]对应值登录

[复制链接]
发表于 2010-2-27 23:04 | 显示全部楼层 |阅读模式

如A列为用户名,B列为密码,如何在用户窗体中的登录框中设置对应关系?谢谢

最佳答案
2010-2-27 23:35

简化点,大致是这样

Private Sub CommandButton1_Click()
   Dim name, pw, n As String
   
   name = ComboBox1.Value
   pw = TextBox1.Value
  
   If name = "" Or pw = "" Then
      MsgBox "用户名或密码不能为空!请输入"
     
   Else
      n = Sheets("用户资料库").Range("C65536").End(xlUp).Row
      n = Sheets("用户资料库").Range("-----" & n).Find(name, SearchOrder:=xlByRows, SearchDirection:=xlNext).Row
     
      If Sheets("用户资料库").Cells(n, 4) = name And Sheets("用户资料库").Cells(n, 5) = pw Then
         -------
       -------
      Else
         MsgBox "信息不对,请重新输入"
      End If
 End If
end sub

发表于 2010-2-27 23:17 | 显示全部楼层

按下用户按钮时,检测输入的用户名为密码是否和资料表上的用户名为密码一致?,如果是,能进入,不对提示重新输入

回复

使用道具 举报

 楼主| 发表于 2010-2-27 23:26 | 显示全部楼层

QUOTE:
以下是引用溦兰在2010-2-27 23:17:00的发言:

按下用户按钮时,检测输入的用户名为密码是否和资料表上的用户名为密码一致?,如果是,能进入,不对提示重新输入

是这个意思,可以如何实现呀?

回复

使用道具 举报

发表于 2010-2-27 23:27 | 显示全部楼层

Private Sub CommandButton1_Click()
   Dim name, str, n As String
   Dim pw As String   
   name = ComboBox1.Value
   pw = TextBox1.Value
  
   If name = "" Or pw = "" Then
      MsgBox "用户名或密码不能为空!请输入", 64
     
   Else
      n = Sheets("用户资料库").Range("C65536").End(xlUp).Row
      n = Sheets("用户资料库").Range("----").Find(name, SearchOrder:=xlByRows, SearchDirection:=xlNext).Row
      str = Sheets("用户资料库").Cells(n, 4)
     
      If Sheets("用户资料库").Cells(n, 4) = name And Sheets("用户资料库").Cells(n, 5) = pw Then
         -------
       -------
      Else
         MsgBox "信息不对,请重新输入"
      End If
 End If
end sub
回复

使用道具 举报

发表于 2010-2-27 23:35 | 显示全部楼层    本楼为最佳答案   

简化点,大致是这样

Private Sub CommandButton1_Click()
   Dim name, pw, n As String
   
   name = ComboBox1.Value
   pw = TextBox1.Value
  
   If name = "" Or pw = "" Then
      MsgBox "用户名或密码不能为空!请输入"
     
   Else
      n = Sheets("用户资料库").Range("C65536").End(xlUp).Row
      n = Sheets("用户资料库").Range("-----" & n).Find(name, SearchOrder:=xlByRows, SearchDirection:=xlNext).Row
     
      If Sheets("用户资料库").Cells(n, 4) = name And Sheets("用户资料库").Cells(n, 5) = pw Then
         -------
       -------
      Else
         MsgBox "信息不对,请重新输入"
      End If
 End If
end sub

回复

使用道具 举报

 楼主| 发表于 2010-2-28 09:46 | 显示全部楼层

 n = Sheets("用户资料库").Range("-----" & n).Find(name, SearchOrder:=xlByRows, SearchDirection:=xlNext).Row

到这里出错了,

回复

使用道具 举报

发表于 2010-2-28 10:16 | 显示全部楼层

 n = Sheets("用户资料库").Range("-----" & n)这里是要你写入你自己选的区域呀,我不知道你的区域在那,所以就用----来代替
回复

使用道具 举报

 楼主| 发表于 2010-2-28 10:51 | 显示全部楼层

用户资料工作表中的A列为用户名,B列为密码,要怎么写呢?

回复

使用道具 举报

 楼主| 发表于 2010-2-28 10:56 | 显示全部楼层

Private Sub CommandButton1_Click()
   Dim name, str, n As String
   Dim pw As String
   name = TextBox1.Value
   pw = TextBox2.Value
  
   If name = "" Or pw = "" Then
      MsgBox "用户名或密码不能为空!请输入", 64
     
   Else
      n = Sheets("用户").Range("A65536").End(xlUp).Row
      n = Sheets("用户").Range("A:B").Find(name, SearchOrder:=xlByRows, SearchDirection:=xlNext).Row
      str = Sheets("用户").Cells(n, 1)
     
      If Sheets("用户").Cells(n, 1) = name And Sheets("用户").Cells(n, 2) = pw Then
       MsgBox "登录成功!"

Unload UserForm1
Application.Visible = True
      Else
         MsgBox "信息不对,请重新输入"
      End If
 End If
End Sub

这样对吗?

回复

使用道具 举报

发表于 2011-8-20 11:34 | 显示全部楼层
都是高手              
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-31 15:07 , Processed in 1.514955 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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