473,409 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

data validation on a combination of two fields

Hello Bytes/Scripts folks!

I am trying to implement validation for a combination of two fields in a table (through a form). I have a form “frmAddAddr2” that is bound to the table “tblLKUPAddr2”. frmAddAddr2 pops-up when a user is entering an address in the main form and does not find their Addr2 option in the main form’s combo box “cboAddr2”. (Addr2 in this case is the second line of an address i.e. Apt 1B or Ste 701).

On the main form cboAddr2 shows the Addr2 values as a concatenation of two fields in tblLKUPAddr2: “Addr2Prefix”, which is the prefix Apt, Ste, Fl part of Addr2, and “Addr2Nm”, which is the number part of Addr2. I made Addr2 two fields because I wanted to control the spelling of the prefix so that I didn’t end up with unintended duplicates such as Suite 3, Ste 3, St 3. This way, you choose the prefix and then the number and they are concatenated in the query for the main form’s cboAddr2.

On the pop-up form, frmAddAddr2, the user chooses the prefix from a combo box cboAddr2Prefix and then enters the number in txtAddr2Nm. What I would like to do is to check that the combination of the values in these fields does not already exist in tblAddr2. I have read some of the data validation threads and got as far as getting the following DLookup code - posted below - to work in the BeforeUpdate event of a single field (Addr2Nm). However, I cannot figure out how to alter the code to work on a combination of both fields.
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtAddr2Nm_BeforeUpdate(Cancel As Integer)
  2.  
  3.   If DCount("[Addr2Nm]", "[tblLKUPAddr2]", "[Addr2Nm] = '" & Trim$(Nz(Me.txtAddr2Nm)) & "'") > 0 Then
  4.      MsgBox "That Addr2 already exists."
  5.  
  6. End If
  7.  
  8. End Sub
Any advice is greatly appreciated!

Bridget
Apr 24 '08 #1
4 2529
PS. Validating based on two fields seems like it will be useful for other items in my database as well. For example, when adding a street address it is possible there could legitimately be two identical values in the "Addr1" field, but only if the values in the "ZipCode" field are different (e.g. 10 5th St in Brookyn, NY 11231 and 10 5th St in New Rochelle, NY 10801). So, I would want to see if a combination of values in the field Addr1 and ZipCode already exists.

Thanks again for any suggestions!
Bridget
Apr 24 '08 #2
NeoPa
32,556 Expert Mod 16PB
You need to specify the third parameter of your DCount() function carefully.

The first is probably better off simply as "*". The second is fine. The third needs to select the actual matching records using SQL WHERE syntax.
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtAddr2Nm_BeforeUpdate(Cancel As Integer)
  2.   Dim strWhere As String
  3.  
  4.   strWhere = "[Addr2Prefix]='%1' AND [Addr2Nm]='%2'"
  5.   strWhere = Replace(strWhere, "%1", Me.cboAddr2Prefix)
  6.   strWhere = Replace(strWhere, "%2", Trim(Nz(Me.txtAddr2Nm)))
  7.   If DCount("*", "[tblLKUPAddr2]", strWhere) > 0 Then
  8.      MsgBox "That Addr2 already exists."
  9.   End If
  10. End Sub
Apr 25 '08 #3
Thanks for the reply NeoPa. I will try and post back if I have problems.
Bridget
Apr 25 '08 #4
NeoPa
32,556 Expert Mod 16PB
No worries Bridget :)

I particularly appreciated that all the information I needed was available in the question.
Apr 25 '08 #5

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

Similar topics

10
by: sffan | last post by:
I am new to database programming and was curious how others solve the problem of storing encrypted in data in db table columns and then subsequently searching for these records. The particular...
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
0
by: Jason | last post by:
I have a primary form which is used to enter/edit data in a table named Test_Results. On this primary form there is a subform which displays site addresses. This subform is linked to the primary...
0
by: Daron | last post by:
I know that somebody has done this, So basically I am seeking examples and ideas. At work we use a db to validate various text files. The text files follow a specific known format. We run a...
2
by: Jeremy S | last post by:
In a Web Forms application I present users with a list of items - each of which the user is to assign to a grid. The grid is N rows by 3 columns. The users enter the desired target cell for each...
2
by: Dnna | last post by:
I have a table which is bound to an Internet Explorer XML data island. I'm using ASP.NET's client-side validators for an input field in the table. The problem is that if the input fields are in...
12
by: Dabbler | last post by:
I need to insure that at least one of three phone number fields has a value (requiredfield) but I'm not sure of a way to implement this without server side logic. Is there a way to use the...
20
by: hippomedon | last post by:
Hello everyone, I'm looking for some advice on whether I should break the normalization rule. Normally, I would not consider it, but this seems to be a special case. I have created an...
1
by: DBlearner | last post by:
I'm surprised I couldnt find a question about this here so guess I better ask. I have a form with two date fields. and . Obviously, Enddate cannot predate Startdate field so I decided to do a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...

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.