where will i use it?

meenctg

Learn24bd
Local time
Tomorrow, 04:12
Joined
May 8, 2012
Messages
133
I have a login form in my database. i used vb code for this form

Code:
Private Sub Command31_Enter()
If Me.valita = "abc123" Then
        DoCmd.OpenForm "start"
    Else
        DoCmd.OpenForm "wrong_pass"
   End If
End Sub

but after login success entered password the login form remain open. i know close code will be
DoCmd.Close acForm, "login"

but i don't understand where will i use it? please any body help me to solve this task.
 
First off, you have your code in the wrong event. It should not be in the ENTER event (Enter does not mean pressing Enter, it means essentially that you have arrived at the control). It should be in the CLICK event of the command button.

Second, it would be just after the End If.

Third, you can write it generically so you don't have to write it special for any form. As long as it is being run by an event on that specific form, you can use:

DoCmd.Close acForm, Me.Name, acSaveNo

The Me.Name remains just as I typed as it will then be the name of the form which the code is on which it receives. And I suggest the acSaveNo as the default is to prompt the user to save DESIGN CHANGES to the form. It has nothing to do with saving records. So you don't want the user to save design changes to the form, so use acSaveNo.
 

Users who are viewing this thread

Back
Top Bottom