VBA Login Form not Working

Amitdas

New Member
Joined
Apr 27, 2019
Messages
22
Hi, Expert I am new in a Excel. I went to get you expert solution for Excel VBA. I create a Excel Data entry UserForm & Excel LogIn From Option. But I face some Problems, When I open the Excel file then First show log in option But when I cancel the loginform then it show my Data Entry userform2. This issue is my Problems.

NB: login Form1 is working but when i cancel then it show the Data Entry Form2.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Sounds like you have code in Form 1 that opens Form 2, when Form 1 is closed.

Post your code here for review.
 
Upvote 0
Private Sub Workbook_Open()Application.Visible = False
UserForm2.Show


Dim expiry As Date
expiry = "8/10/2020"
If Date > expiry Then
MsgBox "The data has expired. Please Contract Amit Das 01724115657", vbInformation, "Close"
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.Quit
Else
End If


UserForm1.Show


End Sub
 
Upvote 0
The macro you posted runs when the workbook is initially opened.

Immediately the code open UserForm2 : UserForm2.Show

After checking the current date against the date included in the macro, it then moves on to open
UserForm1 :
UserForm1.Show


I am presuming your Login Form is UserForm1 ? If so, when you close that, UserForm2 is still open, so
it appears underneath where your UserForm1 was located.

If UserForm2 is not needed when the workbook first opens, delete that first line from the macro :
UserForm2.Show
 
Upvote 0
UserForm2 = Login Form
UserForm1 = Data Entry Form

When UserForm2 is open we shall input Id Password to open Userform1 but unfortunately if i close userform2 without use Id password and close UserForm2 then automatically UserForm1 is Opening.

In the other case when I Close UserForm1 then all are close. But when i am trying to open the same Excel again UserForm2 is not showing Directly active Work Sheet.

Can you Please Help me to provide the Code.
Thanks in advance.
 
Upvote 0
.
This is part of the code. Review the macros in both forms, the module and ThisWorkbook Module :

Code:
Option Explicit


Private Sub CommandButton1_Click()
    If Me.TextBox1.Text = "Username" Then
        If Me.TextBox2.Text = "PW" Then
            Unload Me
            UserForm2.Show
        End If
    Else
        MsgBox "Wrong Username or Password. ", vbCritical, "LogIn Error"
        Unload Me
    End If
End Sub


Private Sub CommandButton2_Click()
    Unload Me
End Sub


Download workbook : https://www.amazon.com/clouddrive/share/p3tS3mCMrJHRw6Q3e6qYfIKnzynB2mM5lMWaSQXkzpB
 
Upvote 0
Thank you very much for your workings which is send to me. Yes my problems is solved now but another Problem has been occurred here. e.g. If i open the Excel sheet then Showing LogIn form it is right hear. If i wish to not work currently and close all of things and if i reopen the Excel then logIn form is not showing and open worksheet. Without LonIn Form any of future sheet should not be opened here.

Can you please help to solved this issue
Thanks in Advance.
 
Upvote 0
.
When the workbook is opened, everything is hidden except the LOGIN user form.

If the user clicks on QUIT at that point, the workbook is closed.

Was there something else you wanted it to do ? Did I misunderstand your question ?


Also, I don't believe there is any difference whether your workbook is the ONLINE version of Excel or it is used
on your desktop computer, as mine is. I do not have Excel 365 Online. I use Excel 2007 on my computer at home.
BUT ... that should not make a difference in how the workbook responds. The macro code is still the same and the
workbook should function as desired with the current code.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,841
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top