473,399 Members | 3,603 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,399 software developers and data experts.

No duplicates in form

266 256MB
i have a form that lists addresses and also a check box if the address has been given a notice, and then a second check box for two notices and so on up to three. the address field is actually 2 fields, one field (num) is for the house number and the other field (street) is for the street. the street field is a combo box with a source table listing all of the street names that i will use, as to avoid typos and such. what i would like to do, is when i type in a number and street into the two above mentioned fields, if the address already exists in the form, i would like it to popup a message box letting me know if already exists, and perhaps even take me to the record if possible. i have come close but only by combining the two fields (num, street) into one field called 'location' and obviously eliminating the combo box feature, which can now lead to typos. i have used the following code in the after update event of the 'location' field

Expand|Select|Wrap|Line Numbers
  1. Dim SID As String
  2. Dim stLinkCriteria As String
  3. Dim rsc As DAO.Recordset
  4.  
  5. Set rsc = Me.RecordsetClone
  6.  
  7. SID = Me.LOCATION.Value
  8. stLinkCriteria = "[LOCATION]=" & "'" & SID & "'"
  9.  
  10.     'Check StudentDetails table for duplicate StudentNumber
  11.     If DCount("LOCATION", "MASTER", stLinkCriteria) > 0 Then
  12.         'Undo duplicate entry
  13.         Me.Undo
  14.         'Message box warning of duplication
  15.         MsgBox "Address " _
  16.         & SID & " has already been entered." _
  17.         & vbCr & vbCr & "You will now been taken to the record.", vbInformation _
  18.         , "Duplicate Information"
  19.         'Go to record of original Student Number
  20.         rsc.FindFirst stLinkCriteria
  21.         Me.Bookmark = rsc.Bookmark
  22.     End If
  23.  
  24. Set rsc = Nothing
any idea how i can achieve this with the two separate fields and still maintaining my combo box feature? thanks!
Aug 2 '11 #1
5 2508
ADezii
8,834 Expert 8TB
Here is the General Idea as to how I would proceed on this matter:
  1. Create a Private Sub-Routine in the Form's Code Module (ValidateAddress()) that will do all the work of Validating the Address based on both the [num] and [street] Fields. It can be as sophisticated as you wish.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub ValidateAddress()
    2. 'Make sure that there are entries in both the [num] and [street] Fields, and
    3. 'that the [num] Field is Numeric in nature
    4. If IsNull(Me![num]) Or IsNull(Me![cboStreet]) Or Not IsNumeric(Me![num]) Then
    5.   MsgBox "The Current Address cannot be added to the Database"
    6.     Exit Sub
    7. End If
    8.  
    9. 'Check for Duplication in the [num] and [street] Fields
    10. If DCount("*", "tblAddressess", "[num]=" & Me![num] & " And [street] = '" & _
    11.                                  Me![cboStreet] & "'") > 0 Then
    12.   MsgBox "[" & Me![num] & " " & Me![cboStreet] & "] is a Duplicate Address"
    13. Else
    14.   'If you get here, you are good to go
    15. End If
    16. End Sub
  2. Call this Sub-Routine from the AfterUpdate() Events of both the [num] and [street] Fields.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub num_AfterUpdate()
    2.   Call ValidateAddress
    3. End Sub
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboStreet_AfterUpdate()
    2.   Call ValidateAddress
    3. End Sub
  3. Any further questions, feel free to ask.
Aug 3 '11 #2
didacticone
266 256MB
thanks! that worked well, the only thing i did differently was i only called the sub-routine on the street afterupdate event, otherwise i wasnt able to enter the same house number, which obviously there are many... no one more question for you, is there a way that after the popup box letting me know the address already exists, that it can then take me to that record, so i dont have to go looking for it? thanks again!
Aug 3 '11 #3
ADezii
8,834 Expert 8TB
is there a way that after the popup box letting me know the address already exists, that it can then take me to that record, so i dont have to go looking for it?
Yes, just a couple of modifications should do it:
Expand|Select|Wrap|Line Numbers
  1. Dim strCriteria As String
  2. Dim rst As DAO.Recordset
  3. 'Make sure that there are entries in both the [num] and [street] Fields, and
  4. 'that the [num] Field is Numeric in nature
  5. If IsNull(Me![num]) Or IsNull(Me![cboStreet]) Or Not IsNumeric(Me![num]) Then
  6.   MsgBox "The Current Address cannot be added to the Database"
  7.     Exit Sub
  8. End If
  9.  
  10. strCriteria = "[num]=" & Me![num] & " And [street] = '" & Me![cboStreet] & "'"
  11.  
  12. 'Check for Duplication in the [num] and [street] Fields
  13. If DCount("*", "tblAddressess", strCriteria) > 0 Then
  14.   MsgBox "[" & Me![num] & " " & Me![cboStreet] & "] is a Duplicate Address"
  15.  
  16.   Set rst = Me.RecordsetClone
  17.       rst.FindFirst strCriteria
  18.         Me.Bookmark = rst.Bookmark
  19. Else
  20.   'If you get here, you are good to go
  21. End If
Aug 3 '11 #4
didacticone
266 256MB
worked perfectly! thanks for your help!
Aug 3 '11 #5
ADezii
8,834 Expert 8TB
You are quite welcome, glad we got everything to work to your satisfaction.
Aug 3 '11 #6

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

Similar topics

5
by: Papajo | last post by:
I,m looking for a script to remove duplicates email addresses from a list, the addresses will be displayed one per line in a textarea. The script will be used on a simple webtv browser. Thanks Joe
4
by: Danny | last post by:
Ok I am trying to create this 2 Tables 1 form The 1st table has Reference Number, Username, Telephone The 2nd table has Reference Number, 2nd Telephone Well what I would like to do is...
1
by: Manton | last post by:
Access 2000. I have a table called tbl_main There are several fields in this table - two of which are called "Staff Name" and "Account Number". I created a form (frm_data) which is linked to the...
6
by: Marlene | last post by:
Hi All I have the following scenario, where I have found all the duplicates in a table, based on an order number and a part number (item).I might have something like this: Order PODate Rec...
9
by: Tony Williams | last post by:
I have two tables 1.tblmonth which holds two fields txtmonth and txtqtrlabel and 2. tblmain which holds a number of fields but in particular a field called txtqtrlabel2. The two tables are linked...
11
by: Jerry | last post by:
Say a table has four fields: ID (PK) Field1 Field2 Field3 Field 1 is indexed as Yes(No Duplicates) When a duplicate is entered in Field1, nothing happens until you try to save the record then...
6
by: Parasyke | last post by:
I have a form that uses has a series of about 10 different queries to get the final VIEW query to populate my form. I wrote the below to find the duplicates, which works. I don't want to delete the...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
7
by: john.cole | last post by:
I have searched all the groups I can, and I still haven't been able to come up the solution I need. I have the following problem. In my form named sbfrmSpoolList, I am entering a job, spool and...
11
beacon
by: beacon | last post by:
Hi everybody, I created a database that links one table from an ODBC data source. I saved my password and UID to the data source so neither myself nor anyone else would have to login each time...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
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,...
0
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...
0
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,...
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
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...

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.