Solved Login Form Access 2010 (1 Viewer)

vcarrill

Registered User.
Local time
Today, 09:21
Joined
Aug 22, 2019
Messages
60
Hello, I am trying to have a user login with a Username and Password in order to access the frmMain.

I have the following code:

Option Compare Database
Option Explicit

Private Sub btnLogin_Click()
Dim rs As Recordset

Set rs = CurrentDb.OpenRecordset("tblUser", dbOpenSnapshot, dbReadOnly)

rs.FindFirst "UserName='" & Me.txtUserName & "'"

If rs.NoMatch = True Then
Me.lblWrongUser.Visible = True
Me.txtUserName.SetFocus
Exit Sub
End If
Me.lblWrongUser.Visible = False

If rs!Password <> Me.txtPassword Then
Me.lblWrongPassword.Visible = True
Me.txtPassword.SetFocus
Exit Sub
End If
Me.lblWrongPassword.Visible = False
DoCmd.OpenForm "frmMain"
DoCmd.Close acForm, Me.Name
End Sub

Yet I enter the username and password I receive:

Compile error:
Invalid outside procedure

What am I doing wrong?

Thank you
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:21
Joined
Oct 29, 2018
Messages
21,358
Hi. Which line is getting highlighted when you get the error message?
 

vcarrill

Registered User.
Local time
Today, 09:21
Joined
Aug 22, 2019
Messages
60
Hi. Which line is getting highlighted when you get the error message?

A window pops-up with:

1598983680132.png
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:21
Joined
Oct 29, 2018
Messages
21,358
OpenReport is not in my code?
Hi. I can only go by what you posted. I also thought OpenReport had nothing to do with what you're trying to do with user logins, but it appears to be causing an error in your database application, so you may have to handle that first, before you can continue testing your new login feature.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:21
Joined
Feb 19, 2013
Messages
16,553
OpenReport is not in my code?
could be in a different module - you have option explicit set, so compile the code (debug>compile) and fix any errors you might find before continuing
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:21
Joined
Feb 28, 2001
Messages
26,999
Based on the way your image shows the OpenReport action, it does not appear to be in your code correctly.

Your Command23_Click event routine starts a new subroutine. Normally, what we would see just above that divider line above your click routine would be either the tail end of the form's class module data declaration area OR an End Sub or an End Function. The appearance of the OpenReport action in that particular position tells us that whatever was defined BEFORE that click routine was incorrectly terminated.
 

vcarrill

Registered User.
Local time
Today, 09:21
Joined
Aug 22, 2019
Messages
60
Based on the way your image shows the OpenReport action, it does not appear to be in your code correctly.

Your Command23_Click event routine starts a new subroutine. Normally, what we would see just above that divider line above your click routine would be either the tail end of the form's class module data declaration area OR an End Sub or an End Function. The appearance of the OpenReport action in that particular position tells us that whatever was defined BEFORE that click routine was incorrectly terminated.

So I am not an Access programmer by no means, so based on the code I included in my original post, what do I have to change?

Thank you
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:21
Joined
Oct 29, 2018
Messages
21,358
So I am not an Access programmer by no means, so based on the code I included in my original post, what do I have to change?

Thank you
Nothing yet. We're still trying to fix the error message you got. Since it's complaining about OpenReport, I recommended you remove that line (or comment it out) to see if we can move on.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:21
Joined
Feb 28, 2001
Messages
26,999
Find that Command23_Click routine that was in your image in your post #3. In your database's design screens, you can get to the code windows with a control-G and then you can navigate to the code. In the toolbars, you can do a FIND (whole project) for that sequence.

Now scroll up to see what is earlier in that code module than the click routine. The odds are that the click routine is OK but the previous routine is not, so you have to see what it is.

In a module, typical structure is

Code:
Private Sub xxxxx
some Dim statements, perhaps
....
some instructions
....
End Sub

My original comments were because there was something other than an End Sub just before the click routine's entry point declaration. There is such a thing as having data declarations at the top of a form's class module, but OpenReport does not count as a data declaration.
 

Users who are viewing this thread

Top Bottom