Please Help Me, Run Time Error

Xaverria

Registered User.
Local time
Today, 21:33
Joined
Nov 29, 2004
Messages
17
My form should do the following:

1)When user choose their id (Eg: S8745215G) from a combo-box(cboNRIC) and enter their name in a textbox(txtName).

2)The system check to see if the name entered matches the name stored in the table(PARTICULARS)

3)If name entered matches the name stored in the database, i would call out another form. But i need to pass the id into the form.

How should i do that?(Pass id into another form)

Now my problem is that i get the run-time error 2001, Please anyone help me..
Please tell me what's wrong. Thankyou.

--------------------------------------------------------------------------
The following is my code:
--------------------------------------------------------------------------
Option Compare Database
Private intLogonAttempts As Integer

'Check value of name in PARTICULARS to see if this matches value chosen in combo box
If Me.txtName.Value = DLookup("[NAME]", "PARTICULARS", "NRIC =" & Me.cboNRIC.Value)Then
lngMyEmpID = Me.cboNRIC.Value
DoCmd.Close acForm, "LOGIN_MENU", acSaveNo
DoCmd.OpenForm "ALL_INFORMATION_FORM_USER"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtName.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
End Sub
 
Last edited:
If Me.txtName.Value = DLookup("[NAME]", "PARTICULARS", "NRIC = '" & Me.cboNRIC & "'") Then


???
kh
 
Thanks it works...
But how do i pass the cboNRIc.Value into the form?
 
With out looking at the rest of your code, try referencing the combo box with out the .value on the end:

lngMyEmpID = Me.cboNRIC

kh
 
The form is created from a query

SELECT *
FROM PARTICULARS
WHERE ((PARTICULARS.NRIC)=[SESSION_NRIC]);

How do i pass the id into the variable SESSION_NRIC?
 
I would save the value in a public variable and use it as a paremeter in the query builder grid.

???
kh
 
Name is a reserved word in Access, you should change the field name to something else or it will cause you problems
 
Ok. Thanks for the advice..

How do i do that?

How and where should i declare a public variable ?

How do i read it into my query?
 
I have saved it to the public variable (under the same variable name as my query), but it still prompt me to enter a value for the variable. :(
 
In the general section of the login form try something like:

Public MyVarName As String

(substitute whatever you want for 'MyVarName')

Then when the user logs in assign a value to it and simply use this in the query as a parameter...

???
kh
 
I should place it outside the sub procedures, right?

But i try, but still cannot work.
 
Last edited:
Yes - You should play around with the concept of public vars some more - pretty basic and powerfull. :)
 
I think you're almost there - whatever your variable name is, just type that in the query parameter:

like myVariableName

???
kh
 
I place it like this
--------------------------------------------------------------------------
Option Compare Database
Public SESSION_NRIC As String

Private Sub Form_Open(Cancel As Integer)
'On open set focus to combo box
'Completed
Me.cboNRIC.SetFocus
End Sub

Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
'Completed
Me.txtName.SetFocus
End Sub

Private Sub cmdLogin_Click()

'Check to see if data is entered into the password box
'Completed
If IsNull(Me.txtName) Or Me.txtName = "" Then
MsgBox "Please enter your Name.", vbOKOnly, "Required Data"
Me.txtName.SetFocus
Exit Sub
End If

'Check value of password in PARTICULARS to see if this matches value chosen in combo box
'Completed
If Me.cboNRIC.Value = "" Then
If Me.txtName.Value = "Administrator" Then
MsgBox "Welcome System Administrator.", vbOKOnly, "Welcome"
DoCmd.Close acForm, "LOGIN_MENU", acSaveNo
DoCmd.OpenForm "ALL_INFORMATION_FORM_ADMIN"
Exit Sub
End If
End If

'Check value of name in PARTICULARS to see if this matches value chosen in combo box
'Completed
If Me.txtName.Value = DLookup("[NAME]", "PARTICULARS", "NRIC = '" & Me.cboNRIC & "'") Then
SESSION_NRIC = Me.cboNRIC.Value
DoCmd.Close acForm, "LOGIN_MENU", acSaveNo
DoCmd.OpenForm "ALL_INFORMATION_FORM_USER"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtName.SetFocus
Exit Sub
End If
End Sub
--------------------------------------------------------------------------
SESSION_NRIC is the name used also in my sql statement

SELECT *
FROM PARTICULARS
WHERE ((PARTICULARS.NRIC)=[SESSION_NRIC]);

-------------------------------------------------------------------------

But when i run the form, i still prompt me to enter the value for
SESSION_NRIC

What should i do?

Is there any coding that i have to enter to tell the program that the input for sql(SESSION_NRIC) is the same as the SESSION_NRIC of the login form?
 
Hang on a minute and let me get my head around this - I've been doing three things at once here....

Which is the user name and which is the password:

txtName = Username or password?
cboNRIC = Username or password?

What does NRIC stand for?

???
kh
 

Users who are viewing this thread

Back
Top Bottom