Hi
On exiting a National Insurance text box, i want it to validate there are no duplicates.
I have copied some code, which will hopefully count the times National insurance is duplicated and produce a msgbox...
Set rst = dbs.OpenRecordset("SELECT * FROM tblEmployee WHERE (([tblEmployee].[EmpNationalInsuranceNo]) =" _
& Me.TNI & ");")
getting error on the bottom line, i cant see where i'm going wrong.. Maybe closing brackets?
Run time error 3075
Syntax error (Missing operator) in query expression
Set rst = dbs.OpenRecordset("SELECT * FROM tblEmployee WHERE (([tblEmployee].[EmpNationalInsuranceNo]) = 'TN120777F)' AND (([tblEmployee].[EmpRegNo]) <> '10);'
If an easier method could be used, all help would be appreciated..
I tried using Dlookup, but couldnt get that to work properly,
---------USING vLOOKUP-------
'Dim VarX As Variant
'VarX = Nz(DLookup("[EmpNationalInsuranceNo]", "tblEmployee", "[EmpRegNo] = " & Forms![Form1]!tReg))
'If VarX = Me.TNI Then
'MsgBox "Someone ALREADY has this NI"
'Else
'MsgBox "This NI is UNIQUE"
'End If
------------------
It would be great to get both methods to work
Thx
Darin
On exiting a National Insurance text box, i want it to validate there are no duplicates.
I have copied some code, which will hopefully count the times National insurance is duplicated and produce a msgbox...
Set rst = dbs.OpenRecordset("SELECT * FROM tblEmployee WHERE (([tblEmployee].[EmpNationalInsuranceNo]) =" _
& Me.TNI & ");")
getting error on the bottom line, i cant see where i'm going wrong.. Maybe closing brackets?
Run time error 3075
Syntax error (Missing operator) in query expression
Set rst = dbs.OpenRecordset("SELECT * FROM tblEmployee WHERE (([tblEmployee].[EmpNationalInsuranceNo]) = 'TN120777F)' AND (([tblEmployee].[EmpRegNo]) <> '10);'
Code:
Private Sub TNI_Exit(Cancel As Integer)
Dim dbs As Database
Dim rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT * FROM tblEmployee WHERE (([tblEmployee].[EmpNationalInsuranceNo]) = '" _
& Me.TNI.Value & ")' AND (([tblEmployee].[EmpRegNo]) <> '" & Me.tReg.Value & ");")
-----USED SAMPLE CODE BUT I'M GETTING ERROR--------
'Set rst = dbs.OpenRecordset("SELECT * FROM tbl1 WHERE (([tbl1].[fld1]) = '" _
& Me.txtFld1.Value & ") AND (([tbl1].[fld2]) = '" & Me.txtFld2.Value & ");")
-------------------------------------------------
If rst.RecordCount > 0 Then ' this is a duplicate entry
' Enter code here
MsgBox "This is DUPLICATE"
Else ' This is not a duplicate entry
' Enter code here
MsgBox "This is NOT dup"
End If
Set rst = Nothing
Set dbs = Nothing
End Sub
If an easier method could be used, all help would be appreciated..
I tried using Dlookup, but couldnt get that to work properly,
---------USING vLOOKUP-------
'Dim VarX As Variant
'VarX = Nz(DLookup("[EmpNationalInsuranceNo]", "tblEmployee", "[EmpRegNo] = " & Forms![Form1]!tReg))
'If VarX = Me.TNI Then
'MsgBox "Someone ALREADY has this NI"
'Else
'MsgBox "This NI is UNIQUE"
'End If
------------------
It would be great to get both methods to work
Thx
Darin