首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

高手,多谢

2012-02-09 
高手请指教,谢谢Private Sub cmdSave_Click()Dim objCopy As New RecordsetIf Len(Trim(txtUser)) 5 Th

高手请指教,谢谢
Private Sub cmdSave_Click()
  Dim objCopy As New Recordset
  If Len(Trim(txtUser)) <> 5 Then
  MsgBox "用户编号必须为5位字符串!", vbCritical, "系统用户管理"
  txtUser.SetFocus
  txtUser.SelStart = 0
  txtUser.SelLength = Len(txtUser)
  ElseIf Len(Trim(txtPWD)) <> 6 Then
  MsgBox "用户口令必须为6位字符串!", vbCritical, "系统用户管理"
  txtPWD.SetFocus
  txtPWD.SelStart = 0
  txtPWD.SelLength = Len(txtPWD)
  ElseIf Not cmbStatus Like "[0,1,2,3,4]" Then
  MsgBox "用户权限代码必须为0、1、2、3或4!", vbCritical, "系统用户管理"
  cmbStatus = "": cmbStatus.SetFocus
  Else
  Set objCopy = Drug_Store.rsSysUsers.Clone
  With objCopy
  If .RecordCount > 0 Then
  .MoveFirst
  .Find "编号=""&Trim(txtUser)&"""
  If Not .EOF And .AbsolutePosition <> _
  Drug_Store.rsSysUsers.AbsolutePosition Then
  MsgBox "编号:" & Trim(txtUser) & _
  "已被使用,请使用其他用户名!", _
  vbCritical, "系统用户管理"
  txtUser.SetFocus
  txtUser.SelStart = 0
  txtUser.SelLength = Len(txtUser)
  Exit Sub
  End If
  End If
  End With
  Drug_Store.rsSysUsers.Update
  MsgBox "数据保存成功!", vbInformation, "系统用户管理"
  cmdAdd.Enabled = True
  cmdDelete.Enabled = True
  isAding = False
  picNavigation.Enabled = True
   
  End If
   
End Sub

要求对象 实时错误‘424’
是什么错误?请各位大侠帮帮忙!


[解决办法]
如果是因为禁用,那错误提示是“无效的过程调用或参数”而不是“要求对象”。

“要求对象”说明引用的对象是不存在的!


我最怀疑的是楼主把控件名称搞错了。

[解决办法]

探讨
引用:
你的保存按钮和txtPWD在同一个窗体上吗?

是的!原来没有加这句:
Dim txtPWD As New Recordset
的时候是要求对象的错误!加了之后就是:未找到方法或数据成员。
错误!

[解决办法]
txtPWD所在窗体名.txtPWD.SetFocus 试试。
Dim txtPWD As New Recordset 这句话不要,或者换个名称。

[解决办法]
txtPWD.SetFocus 
txtPWD.SelStart = 0 
txtPWD.SelLength = Len(txtPWD)
这几个前面都加上所在的窗体名试试

热点排行