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 - Dim SID As String
-
Dim stLinkCriteria As String
-
Dim rsc As DAO.Recordset
-
-
Set rsc = Me.RecordsetClone
-
-
SID = Me.LOCATION.Value
-
stLinkCriteria = "[LOCATION]=" & "'" & SID & "'"
-
-
'Check StudentDetails table for duplicate StudentNumber
-
If DCount("LOCATION", "MASTER", stLinkCriteria) > 0 Then
-
'Undo duplicate entry
-
Me.Undo
-
'Message box warning of duplication
-
MsgBox "Address " _
-
& SID & " has already been entered." _
-
& vbCr & vbCr & "You will now been taken to the record.", vbInformation _
-
, "Duplicate Information"
-
'Go to record of original Student Number
-
rsc.FindFirst stLinkCriteria
-
Me.Bookmark = rsc.Bookmark
-
End If
-
-
Set rsc = Nothing
any idea how i can achieve this with the two separate fields and still maintaining my combo box feature? thanks!
5 2508
Here is the General Idea as to how I would proceed on this matter: - 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.
- Private Sub ValidateAddress()
-
'Make sure that there are entries in both the [num] and [street] Fields, and
-
'that the [num] Field is Numeric in nature
-
If IsNull(Me![num]) Or IsNull(Me![cboStreet]) Or Not IsNumeric(Me![num]) Then
-
MsgBox "The Current Address cannot be added to the Database"
-
Exit Sub
-
End If
-
-
'Check for Duplication in the [num] and [street] Fields
-
If DCount("*", "tblAddressess", "[num]=" & Me![num] & " And [street] = '" & _
-
Me![cboStreet] & "'") > 0 Then
-
MsgBox "[" & Me![num] & " " & Me![cboStreet] & "] is a Duplicate Address"
-
Else
-
'If you get here, you are good to go
-
End If
-
End Sub
- Call this Sub-Routine from the AfterUpdate() Events of both the [num] and [street] Fields.
- Private Sub num_AfterUpdate()
-
Call ValidateAddress
-
End Sub
- Private Sub cboStreet_AfterUpdate()
-
Call ValidateAddress
-
End Sub
- Any further questions, feel free to ask.
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!
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: - Dim strCriteria As String
-
Dim rst As DAO.Recordset
-
'Make sure that there are entries in both the [num] and [street] Fields, and
-
'that the [num] Field is Numeric in nature
-
If IsNull(Me![num]) Or IsNull(Me![cboStreet]) Or Not IsNumeric(Me![num]) Then
-
MsgBox "The Current Address cannot be added to the Database"
-
Exit Sub
-
End If
-
-
strCriteria = "[num]=" & Me![num] & " And [street] = '" & Me![cboStreet] & "'"
-
-
'Check for Duplication in the [num] and [street] Fields
-
If DCount("*", "tblAddressess", strCriteria) > 0 Then
-
MsgBox "[" & Me![num] & " " & Me![cboStreet] & "] is a Duplicate Address"
-
-
Set rst = Me.RecordsetClone
-
rst.FindFirst strCriteria
-
Me.Bookmark = rst.Bookmark
-
Else
-
'If you get here, you are good to go
-
End If
worked perfectly! thanks for your help!
You are quite welcome, glad we got everything to work to your satisfaction.
Sign in to post your reply or Sign up for a free account.
Similar topics
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |