Selasa, 06 Oktober 2015

RE: [MS_AccessPros] Can't open form.

 

I'm not sure if this is your problem but it looks like you are closing the logon form and causing Me.user.value to go out of scope then trying to use it as a parameter when opening the next form.

Is there code in frmEmployeeWelcome that prevents it from opening without a valid user name?

Either save me.user.value to a variable and use that or try reversing the last two lines from

 

DoCmd.Close "frmLogon", acSaveNo
DoCmd.OpenForm "frmEmployeeWelcome", , , "CompanyEmployeeUserName='" & Me.User.Value & "'", acFormReadOnly

 

To

 

DoCmd.OpenForm "frmEmployeeWelcome", , , "CompanyEmployeeUserName='" & Me.User.Value & "'", acFormReadOnly

DoCmd.Close "frmLogon", acSaveNo

 

 

Bob Peterson

.

 

From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com]
Sent: Tuesday, October 06, 2015 4:02 AM
To: MS_Access_Professionals
Subject: Re: [MS_AccessPros] Can't open form.

 




Dear All,

I send the wrong one. 

I can't open the expected form, please check what's wrong with my code, thank.

 

Private Sub Command4_Click()
On Error GoTo ErrHandle

If IsNull(Me.User) Then
  MsgBox "Please enter username", vbOKOnly, "Username required"
  Me.User.SetFocus
ElseIf IsNull(Me.Password) Then
  MsgBox "Please enter password", vbOKOnly, "Password required"
  Me.Password.SetFocus
  
Else
'test if username and password is correct
  If (IsNull(DLookup("[CompanyEmployeeUserName]", "tblCompanyEmployee", "[CompanyEmployeeUserName]='" & Me.User.Value & "' And [CompanyEmployeePassword]='" & Me.Password.Value & "'"))) Then
  Me.User.SetFocus
    MsgBox "Incorrect username or password", vbOKOnly, "Access Denied"
    Else
    
    DoCmd.Close "frmLogon", acSaveNo
    DoCmd.OpenForm "frmEmployeeWelcome", , , "CompanyEmployeeUserName='" & Me.User.Value & "'", acFormReadOnly
    
    End If
End If

ErrExit:
    Exit Sub
    
ErrHandle:
    Resume ErrExit


End Sub

 


Regards,

Kevin Zhao

 

Date: 2015-10-06 15:48

Subject: [MS_AccessPros] Can't open form.

 

Dear all,

 

I have logon form "frmLogon", and I put the following code in to a command button. The problem is that the expected form didn't open. Please check what's wrong with my code? Thanks.

 

Private Sub Command4_Click()
On Error GoTo ErrHandle

If IsNull(Me.User) Then
  MsgBox "Please enter username", vbOKOnly, "Username required"
  Me.User.SetFocus
ElseIf IsNull(Me.Password) Then
  MsgBox "Please enter password", vbOKOnly, "Password required"
  Me.Password.SetFocus
  
Else
'test if username and password is correct
  If (IsNull(DLookup("[CompanyEmployeeUserName]", "tblCompanyEmployee", "[CompanyEmployeeUserName]='" & Me.User.Value & "' And [CompanyEmployeePassword]='" & Me.Password.Value & "'"))) Then
  Me.User.SetFocus
    MsgBox "Incorrect username or password", vbOKOnly, "Access Denied"
    Else
    DoCmd.Close acForm, "frmLogon", acSaveNo    

    DoCmd.OpenForm "frmEmployeeWelcome", , , "CompanyEmployeeUserName='" & Me.User.Value & "'", acFormReadOnly
    
    End If
End If

ErrExit:
    Exit Sub
    
ErrHandle:
    Resume ErrExit

End Sub

 

 


Regards,

Kevin Zhao




__._,_.___

Posted by: "Robert Peterson" <Bob@AlternateFinishing.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)

.

__,_._,___

Tidak ada komentar:

Posting Komentar