Office中国论坛/Access中国论坛

标题: 如何写这个语句 [打印本页]

作者: tang6518    时间: 2004-9-17 22:26
标题: 如何写这个语句
上次参照了黄海班主的登陆事例.想完成如下的功能:

登陆后,根据不同的登陆ID,来决定打开不同的窗体.

黄海老大的原格式为:

Private Sub cmdOK_Click()

    If IsNull(Me.cboUserName) Then

        MsgBox "请输入您的用户名!", vbQuestion

        Exit Sub

    End If

    If login = True Then

        DoCmd.Close acForm, "登陆背景"

        Me.TimerInterval = 0

        DoCmd.Close acForm, Me.Name

        DoCmd.OpenForm "控制台"

    Else

        MsgBox "用户名或密码不正确!", vbCritical

        Exit Sub

    End If

End Sub

我更改后为: 其中admin是指为以admin的名义登陆.

Private Sub cmdOK_Click()

Dim nm As String

    If IsNull(Me.cboUserName) Then

        MsgBox "请输入您的用户名!", vbQuestion

        Exit Sub

    End If

    If login = True Then

    nm = Me.cboUserName.Value

    If nm = "admin" Then

        DoCmd.Close acForm, "登陆背景"

        Me.TimerInterval = 0

        DoCmd.Close acForm, Me.Name

        DoCmd.OpenForm "主要控制模板"

    ElseIf nm <> "admin" Then

    DoCmd.Close acForm, "登陆背景"

        Me.TimerInterval = 0

        DoCmd.Close acForm, Me.Name

        DoCmd.OpenForm "form1"

    Else

        MsgBox "用户名或密码不正确!", vbCritical

        Exit Sub

   

    End If

    End If

   

End Sub

可是出来的多是 form1.

请教!!! 谢谢!
作者: 方漠    时间: 2004-9-19 04:08
If login = True Then

     nm = Me.cboUserName.Value

      If nm = "admin" Then

        DoCmd.Close acForm, "登陆背景"

        Me.TimerInterval = 0

        DoCmd.Close acForm, Me.Name

        DoCmd.OpenForm "主要控制模板"

      ElseIf nm <> "admin" Then

        DoCmd.Close acForm, "登陆背景"

        Me.TimerInterval = 0

        DoCmd.Close acForm, Me.Name

        DoCmd.OpenForm "form1"

      End If

Else

      MsgBox "用户名或密码不正确!", vbCritical

      Exit Sub

      

End If
作者: 异乡客    时间: 2004-9-20 19:54
endif的位置错了?




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3