A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Even an error with this code I copied



 
 
Thread Tools Display Modes
  #1  
Old June 6th, 2010, 02:41 PM posted to microsoft.public.access.forms
Bob H[_4_]
external usenet poster
 
Posts: 161
Default Even an error with this code I copied

I found a password login system for Access and copied it to aon click
event on a form in Access 2007, but there is an error in the coding.

I have created a tblEmployees with the following fields:
IngEmpID
strEmpName
strEmpPassword
Then I put a unbound combo box on a form with the username and password
fields. The combo box gets a list from strEmpName in the tblEmployees

I then copied the code given into the on click event of the cmd button:
BUT there is a Compile error 'variable not defined' IngMyEmpID, as
shown below

'Check to see if data is entered into the UserName combo box

If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If

'Check value of password in tblEmployees to see if this
'matches value chosen in combo box

If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", _
"[lngEmpID]=" & Me.cboEmployee.Value) Then

lngMyEmpID = Me.cboEmployee.Value
BUT here there is a Compile error 'variable not defined' IngMyEmpID

'Close logon form and open splash screen

DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "frmSplash_Screen"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.txtPassword.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts 3 Then
MsgBox "You do not have access to this database.Please contact
admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If

Thanks
  #2  
Old June 6th, 2010, 02:48 PM posted to microsoft.public.access.forms
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Even an error with this code I copied

Have you declared lngMyEmpID in your code?

I.e. do you have the following statement anywhere?

Dim lngMyEmpID As Long

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/djsteele
Co-author: "Access 2010 Solutions", published by Wiley
(no e-mails, please!)



"Bob H" wrote in message
...
I found a password login system for Access and copied it to aon click event
on a form in Access 2007, but there is an error in the coding.

I have created a tblEmployees with the following fields:
IngEmpID
strEmpName
strEmpPassword
Then I put a unbound combo box on a form with the username and password
fields. The combo box gets a list from strEmpName in the tblEmployees

I then copied the code given into the on click event of the cmd button:
BUT there is a Compile error 'variable not defined' IngMyEmpID, as shown
below

'Check to see if data is entered into the UserName combo box

If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If

'Check value of password in tblEmployees to see if this
'matches value chosen in combo box

If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", _
"[lngEmpID]=" & Me.cboEmployee.Value) Then

lngMyEmpID = Me.cboEmployee.Value
BUT here there is a Compile error 'variable not defined' IngMyEmpID

'Close logon form and open splash screen

DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "frmSplash_Screen"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.txtPassword.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts 3 Then
MsgBox "You do not have access to this database.Please contact
admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If

Thanks


  #3  
Old June 6th, 2010, 04:32 PM posted to microsoft.public.access.forms
Bob H[_4_]
external usenet poster
 
Posts: 161
Default Even an error with this code I copied

On 06/06/2010 14:48, Douglas J. Steele wrote:
Have you declared lngMyEmpID in your code?

I.e. do you have the following statement anywhere?

Dim lngMyEmpID As Long

I didn't actually, thanks.

But now I get another Runtime error '2471':
The expression you entered as a query paramter produced this error:
IngMyEmpID

And when I debug, this is highlighted:

If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", _
"lngMyEmpID=" & Me.cboEmployee.Value) Then

Thanks
  #4  
Old June 6th, 2010, 05:21 PM posted to microsoft.public.access.forms
Bob H[_4_]
external usenet poster
 
Posts: 161
Default Even an error with this code I copied

On 06/06/2010 16:32, Bob H wrote:
On 06/06/2010 14:48, Douglas J. Steele wrote:
Have you declared lngMyEmpID in your code?

I.e. do you have the following statement anywhere?

Dim lngMyEmpID As Long


Apologies, I missed out the square brackets, but the error is still the
same.

I didn't actually, thanks.

But now I get another Runtime error '2471':
The expression you entered as a query paramter produced this error:
IngMyEmpID

And when I debug, this is highlighted:

If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", _
"[lngMyEmpID=]" & Me.cboEmployee.Value) Then

Thanks


  #5  
Old June 6th, 2010, 05:56 PM posted to microsoft.public.access.forms
Bob H[_4_]
external usenet poster
 
Posts: 161
Default Even an error with this code I copied

On 06/06/2010 17:21, Bob H wrote:
On 06/06/2010 16:32, Bob H wrote:
On 06/06/2010 14:48, Douglas J. Steele wrote:
Have you declared lngMyEmpID in your code?

I.e. do you have the following statement anywhere?

Dim lngMyEmpID As Long


Apologies, I missed out the square brackets, but the error is still the
same.

I didn't actually, thanks.

But now I get another Runtime error '2471':
The expression you entered as a query paramter produced this error:
IngMyEmpID

And when I debug, this is highlighted:

If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", _
"[lngMyEmpID=]" & Me.cboEmployee.Value) Then

Thanks



I have just found that I need to create a module and put this line in it

Public lngMyEmpID As Long

So when that is done how does it link to the form or button.

Thanks
  #6  
Old June 7th, 2010, 01:10 PM posted to microsoft.public.access.forms
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Even an error with this code I copied

If by creating a module and adding that line you're talking about putting
the declaration into a second module (i.e. not the module in which the rest
of your code is running), I'd suggest you solved the symptom but not the
problem.

A large part of the problem trying to help you is that you're only giving
little snippets of code without any context. How are you currently running
the code? Your declaration should likely be in that procedure.

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"Bob H" wrote in message
...
On 06/06/2010 17:21, Bob H wrote:
On 06/06/2010 16:32, Bob H wrote:
On 06/06/2010 14:48, Douglas J. Steele wrote:
Have you declared lngMyEmpID in your code?

I.e. do you have the following statement anywhere?

Dim lngMyEmpID As Long


Apologies, I missed out the square brackets, but the error is still the
same.

I didn't actually, thanks.

But now I get another Runtime error '2471':
The expression you entered as a query paramter produced this error:
IngMyEmpID

And when I debug, this is highlighted:

If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", _
"[lngMyEmpID=]" & Me.cboEmployee.Value) Then

Thanks



I have just found that I need to create a module and put this line in it

Public lngMyEmpID As Long

So when that is done how does it link to the form or button.

Thanks



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:37 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.