By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,258 Members | 1,679 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,258 IT Pros & Developers. It's quick & easy.

Login Form

Slaxer13
100+
P: 106
Hi ppl. I am having trouble with a login form. When i click the btnConfirmar, after having both Login and Password it gives me an error 2471: The expression you entered as a query parameter produced this error: the error is whatever value is in the cboLogin.
Anyone has an ideia of what the solution might be?
As an attachment there is a pic of the form.
Any help would be great, Slaxer13.

Expand|Select|Wrap|Line Numbers
  1. Public UtzID As Long
  2.  
  3. Private Sub btnConfirmar_Click()
  4.  
  5.     'Confere se foi escolhido um Login
  6.  
  7.     If IsNull(Me.cboLogin) Or Me.cboLogin = "" Then
  8.       MsgBox "Tem de escolher um LOGIN", vbOKOnly, "Campo Obrigatório"
  9.         Me.cboLogin.SetFocus
  10.         Exit Sub
  11.     End If
  12.  
  13.     'Confere se a password foi introduzida
  14.  
  15.     If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
  16.       MsgBox "Tem de inserir PASSWORD", vbOKOnly, "Campo Obrigatório"
  17.         Me.txtPassword.SetFocus
  18.         Exit Sub
  19.     End If
  20.  
  21.     'Confere se a password é igual ao do login na tblUtilizador
  22.  
  23.     If Me.txtPassword.Value = DLookup("Password", "tblUtilizador", "[Cod_Utilizador]=" & Me.cboLogin.Value) Then
  24.  
  25.         UtzID = Me.cboLogin.Value
  26.  
  27.         'Fecha o frmLogin e abre o programa
  28.  
  29.         DoCmd.Close acForm, "frmLogin", acSaveNo
  30.         DoCmd.OpenForm "frmUtente"
  31.  
  32.     Else
  33.       MsgBox "Password Errada! Tente Outra Vez", vbOKOnly, _
  34.             "Password Errada"
  35.         Me.txtPassword.SetFocus
  36.     End If
  37.  
  38.     'Se o utilizador escrever a password mal três vezes a base de dados é fechada
  39.  
  40.     intLogonAttempts = intLogonAttempts + 1
  41.     If intLogonAttempts > 3 Then
  42.       MsgBox "Não tem acesso á basa de dados. Contacte o Administrador.", _
  43.                vbCritical, "Acesso Restrito!"
  44.         Application.Quit
  45.     End If
  46.  
  47. End Sub
  48.  
  49. Private Sub cboLogin_AfterUpdate()
  50.  
  51.     Me.txtPassword.SetFocus
  52.  
  53. End Sub
Attached Images
File Type: jpg Sem Título.jpg (11.6 KB, 98 views)
Jun 26 '14 #1
Share this Question
Share on Google+
5 Replies


twinnyfo
Expert Mod 2.5K+
P: 3,482
Slaxer,

upon which line of code is the error generating itself?
Jun 26 '14 #2

Expert 100+
P: 1,240
You probably misspelled the field name used in the criteria for the Dlookup. Check the spelling of this field:[Cod_Utilizador]

Jim
Jun 26 '14 #3

twinnyfo
Expert Mod 2.5K+
P: 3,482
Is the value of your cboLogin a text value or integer?

If it is a text value then, line 23 should be:

Expand|Select|Wrap|Line Numbers
  1. If Me.txtPassword.Value = DLookup("Password", "tblUtilizador", _
  2.     "[Cod_Utilizador] = '" & Me.cboLogin & "'") Then
I hope this helps!
Jun 26 '14 #4

Slaxer13
100+
P: 106
Thanks for the reply. I found the problem.

Expand|Select|Wrap|Line Numbers
  1.  If Me.txtPassword.Value = DLookup("[Password]", "tblUtilizador", "[Login]='" & Me.cboLogin.Value & "'") Then
The code should be this way (the changes are bold and italic). My bad. But thanks anyway ;)
Cheers, Slaxer13
Jun 26 '14 #5

twinnyfo
Expert Mod 2.5K+
P: 3,482
I see brilliant minds think alike! Glad we could help!
Jun 26 '14 #6

Post your reply

Sign in to post your reply or Sign up for a free account.