473,785 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validation of a field using Access Forms

Hello All,
I am having trouble with this forum I am developing, I have this form
that allows the users to add or modify employee information, and
there's a text box called txtEmployeeLogi n, and this connected to the
field EmpLogin in the database table. Now this field is not a Key
field and it is not required, and not all employees have logins, but
we can't have employees with duplicate logins. How can I go about
coding a check to see if the login exsist before adding or making
change to the employee record?
Nov 12 '05 #1
4 5175
You could use the DLookup function to see if the value exists in the field. Another option
would be to index the field choosing No Duplicates. If you do this, then Access won't
allow a duplicate entry in the field.

--
Wayne Morgan
"Bobbak" <bo****@ottawa. com> wrote in message
news:64******** *************** ***@posting.goo gle.com...
Hello All,
I am having trouble with this forum I am developing, I have this form
that allows the users to add or modify employee information, and
there's a text box called txtEmployeeLogi n, and this connected to the
field EmpLogin in the database table. Now this field is not a Key
field and it is not required, and not all employees have logins, but
we can't have employees with duplicate logins. How can I go about
coding a check to see if the login exsist before adding or making
change to the employee record?

Nov 12 '05 #2
"Wayne Morgan" <co************ *************** @hotmail.com> wrote in message news:<oE******* **********@news svr31.news.prod igy.com>...
You could use the DLookup function to see if the value exists in the field. Another option
would be to index the field choosing No Duplicates. If you do this, then Access won't
allow a duplicate entry in the field.

--
Wayne Morgan


OK I tried the Dlookup code but I keep getting a Datatype mismatch in
criteria error. Here is my code:

Private Sub TextPHONELOGIN_ AfterUpdate()
Dim varX As Variant
If IsNull(Me![TextPHONELOGIN]) = False Then
varX = DLookup("[PHONELOGIN]", "SMS", "[PHONELOGIN] = " &
Me![TextPHONELOGIN])
MsgBox "The Phone Login " & varX & " already exsist",
vbCritical + vbOKOnly
End If
End Sub
Nov 12 '05 #3
If PHONELOGIN is a text field, you need quotes around the value:

varX = DLookup("[PHONELOGIN]", "SMS", & _
"[PHONELOGIN] = '" & Me![TextPHONELOGIN] & "'")

(where that's ' " & Me![TextPHONELOGIN] & " ' "), or

varX = DLookup("[PHONELOGIN]", "SMS", & )
"[PHONELOGIN] = " & Chr$(34) & Me![TextPHONELOGIN] &
Chr$(34))

However, using DLookup like that is going to work: you're always going to be
popping up the message box, even if the PHONELOGIN doesn't exist.

Try:

Private Sub TextPHONELOGIN_ AfterUpdate()
Dim varX As Variant
If IsNull(Me![TextPHONELOGIN]) = False Then
varX = DLookup("[PHONELOGIN]", "SMS", & _
"[PHONELOGIN] = '" & Me![TextPHONELOGIN] & "'")
If Not IsNull(varX) Then
MsgBox "The Phone Login " & varX & " already exists",
vbCritical + vbOKOnly
End If
End If
End Sub

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
"Bobbak" <bo****@ottawa. com> wrote in message
news:64******** *************** ***@posting.goo gle.com...
"Wayne Morgan" <co************ *************** @hotmail.com> wrote in

message news:<oE******* **********@news svr31.news.prod igy.com>...
You could use the DLookup function to see if the value exists in the field. Another option would be to index the field choosing No Duplicates. If you do this, then Access won't allow a duplicate entry in the field.

--
Wayne Morgan


OK I tried the Dlookup code but I keep getting a Datatype mismatch in
criteria error. Here is my code:

Private Sub TextPHONELOGIN_ AfterUpdate()
Dim varX As Variant
If IsNull(Me![TextPHONELOGIN]) = False Then
varX = DLookup("[PHONELOGIN]", "SMS", "[PHONELOGIN] = " &
Me![TextPHONELOGIN])
MsgBox "The Phone Login " & varX & " already exsist",
vbCritical + vbOKOnly
End If
End Sub

Nov 12 '05 #4
> OK I tried the Dlookup code but I keep getting a Datatype mismatch in
criteria error. Here is my code:

Private Sub TextPHONELOGIN_ AfterUpdate()
Dim varX As Variant
If IsNull(Me![TextPHONELOGIN]) = False Then
varX = DLookup("[PHONELOGIN]", "SMS", "[PHONELOGIN] = " &
Me![TextPHONELOGIN])
MsgBox "The Phone Login " & varX & " already exsist",
vbCritical + vbOKOnly
End If
End Sub
You need the text delimters in there...
Private Sub TextPHONELOGIN_ AfterUpdate()

Const cQUOTE As String ="'"
Dim varX As Variant
If IsNull(Me![TextPHONELOGIN]) = False Then
varX = DLookup("[PHONELOGIN]", "SMS", "[PHONELOGIN] = " & cQUOTE &
Me![TextPHONELOGIN] & cQUOTE)
MsgBox "The Phone Login " & varX & " already exsist",
vbCritical + vbOKOnly
End If
End Sub
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
8695
by: Mike | last post by:
I've been trying for the past week to put a simple code together. I have done a LOT of searching, found scripts showing the functions I would like to use, however when I mix them it all goes wrong, somehow I always end up with error messages and functions not working right. Can someone please help me? I have a form, inside is 1 Text Field and 2 Password Fields. What I'm looking to do is: - Make sure password fields are equal - Set...
2
1219
by: yandr | last post by:
I am sure the answer is somewhere, but although I have searched for it I couldn't find it. I am doing form validation and I am checking each field using document.FormName.FieldName.value My problem is that I am using HTML 4 transitional and if I give a name to the form (<form name="something">) it will not validate. I also can't use document.Forms.FieldName because I have multiple forms in each page. The ID tag doesn't seem to work...
11
3001
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
1
1942
by: John Chan | last post by:
Hi, Im doing a maintenance application in ajax and coldfusion at work on IE6 exclusively. I have a save button on each form and i have to do various validations server side and on client side when the user clicks save i.e check that user exists in table, check users password is the same as password in table, check password is valid, check that logged in user is a super user etc etc to get the correct error message. Different forms may or...
3
4160
by: panjap | last post by:
Hello i have had problems with validation with dates, as i find this difficult to insert into my coursework on a shop and ordering goods. Heloo everyone, i am currently struggling on how to insert validation accoring to the date and time on microsoft access i have the field 'order date' and would like to know what method to use to automatically to insert the present date when a new order is made. Also on the field Required_Date to...
10
5724
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the form the control is on? Basically I have a number of controls in a form that are required, and to check it I am setting the Validation Rule to "<>"IsNull" so that when the user tries to tab through/click out of a required area without entering...
1
1455
by: Sergei Riaguzov | last post by:
Hi. I haven't written in PHP too much so I think I should ask how my problem can be solved "the right way". I'm having some forms (actually this is not my code, and actually I haven't got it yet but I see the result). This forms should be filled by user and when filled and when user clickes on the Next button the next page or the same page with filled results and some yellow/red/whatever signs that something was not filled is shown. ...
3
6226
by: satishknight | last post by:
Hi, Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it has to tell then them its wrong information but currently it takes then to a next page and then tells them its incorrect information. This is tedious as every time they enter wrong they will be redirected to a different page and then they have to...
7
5971
by: sharsy | last post by:
Hi guys, I would like to setup a validation rule for a database in microsoft access that restricts data entry so that a certain field can only be filled in if another field has a specific answer (that is selected via a drop down list). Example Field1 - options are "In" or "Out" Field2 - options are "Join" or "Not Joining"
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9485
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10161
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9958
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.