Hello everyone,
I am painfully new to Access and have absolutely no VBA knowledge. I've taken on the the burden of creating a database and up until now I've only used the expression creator or the macro creator to add functionality to my forms.
I understand this is a problem that was discussed here before but I really haven't been able to get the aforementioned solutions to work with my form and was hoping to get some suggestions.
I would like to have a message box come up upon entry of a duplicate name. This is complicated due to my names being broken up into FirstName LastName and MiddleIntial. I hope to have a message box that warns users, but does not prevent entry altogether.
I've tried to use the expression builder to create an expression that could be placed in the beforeupdate for the form, but to no avail, I receive an "Invaild number of arguments" notice upon trying to save.
Here is my expression:
= IIf( DCount([ALL]![Last Name])=0 & DCount([ALL]![First Name])=0 & DCount([ALL]![Middle Intial])=0, Null, MsgBox("Duplicate name entered, continue?",1, "Duplicate Name")))
I know this isn't really the optimal method of pursuing this, again my lack of ability to write VBA code has limited my results. Any leads would be appreciated.
10 6802
Hi,
I have the following expression in a text box on my contact details form:
=IIf(DCount("*","[eqryContactsExtended]","[Contact ID]<>" & Nz([Contact ID],0) & " And [Contact Name] = '" & Replace(Nz([Contact Name]),"'","''") & "'")>0,"POSSIBLE DUPLICATE","")
It displays "POSSIBLE DUPLICATE" if there's a matching name.
I'm too, erm, tired to explain how it works, I wrote it a while back and I'm still learning myself, so I'd need to deconstruct it. What I can tell you is, it works.
You should just be able to replace:
[eqryContactsExtended] with your contacts table.
[Contact ID] with your equivalent primary key.
[Contact Name] is a calculated query field. If you have your name in two fields you can replace this with the two fields with an ampersand between them ("[first] & [last]").
Good luck. I'll check back tomorrow if you need any more info.
Jay
P.S. I just remembered, I took this from the Contact Management Database template from the online template repository for MSO2007. Might be a good place to look.
And I just realised I might have completely missed what you were trying to achieve.
My solution above can't be used to display a MsgBox, it just displays text on the form.
Do you have a specific need for an intrusive MsgBox as opposed to a passive text box in red font? If so, I'll get back to you tomorrow if nobody else has. It's bed time.
Remember you can use a concatenation of fields for comparison purposes, e.g. [FName]&[MInit]&[LName].
NeoPa 32,556
Expert Mod 16PB
I'd use the AfterUpdate events of each of the three controls to call a common procedure which does the check. Essentially, if any of the values is changed then the check should be performed.
A simple DLookup() or DCount() with the Criteria parameter set to filter on all three controls should give you what you need.
I think that the simplest solution is to declare an index, Unique, on all three fields (in table design). Access will do the rest.
Now first I have to make some assumptions, since you lack some details in your original post. As you read my reply please try to think over if you could have included such details in your original post, and try to remember to include them if you start new threads. Assumptions:
Table Name: tbl_Person
Fields:
KEY_Person: Autonumber
tx_FirstName: Text,50
tx_LastName: Text, 50
tx_MiddleInitial: Text 5
On your form, I assume the controls bound to each field are textboxes and named as such:
tb_PersonID
tb_FirstName
tb_LastName
tb_MiddleInitial
In your FORMS BeforeUpdate I would then add the following code: - Private Sub Form_BeforeUpdate(Cancel As Integer)
-
'Check that no user exists with the same name
-
-
'Only perform check for new records
-
If Me.newRecord then
-
Dim lngUserCount as Long
-
lngUserCount=DCount("*","[tbl_Person]", _
-
"[tx_FirstName]='" & Me.tb_FirstName & "' AND " & _
-
"[tx_LastName]='" & Me.tb_LastName & "' AND " & _
-
"[tb_MiddleInitial]'" & Me.tb_MiddleInitial & "'")
-
-
If lngUserCount>0 then
-
Dim intReply as VbMsgBoxResult
-
intReply=Msgbox("Warning: Possible Duplicate Entry detected!" & vbnewline & _
-
"Press Yes to continue Saving," & vbnewline & _
-
"Press No to return and edit" & vbnewline & _
-
"Press Cancel to discard all changes",vbYesNoCancel+vbExclamation)
-
-
Select Case intReply
-
Case vbYes
-
'Allow save
-
Cancel=false
-
Case vbNo
-
'Stop the save
-
Cancel=True
-
Case vbCancel
-
'Stop the save and undo the form
-
Cancel=True
-
Me.Undo
-
End Select
-
End If
-
End If
-
End Sub
NeoPa 32,556
Expert Mod 16PB Mihail:
I think that the simplest solution is to declare an index, Unique, on all three fields (in table design). Access will do the rest.
This is not an appropriate answer for this thread Mihail, as the OP already said (See post #1) : pseudonymn:
I hope to have a message box that warns users, but does not prevent entry altogether.
Please understand that I'm not criticising. We can all overlook important sentences sometimes (I certainly do), but it needs to be pointed out ;-)
Indeed I overlook that, NeoPa.
Also, based on my English skills, I am not sure that I understand well this sentence: "but does not prevent entry altogether". What I understand from that is that the bound controls can be filled with data but duplicates not be allowed at update time. And my suggest should work in this area.
PS
Do not be worried about criticism. I am ( I think :) ) a true male :))))
NeoPa 32,556
Expert Mod 16PB
It actually means that the operator can decide the new record is to be saved, but they must only do so after being warned. Normally, such a situation is unacceptable, but there may be exceptions. Does that make it clearer?
@NeoPa
such a situation is unacceptable, but there may be exceptions
Well... now is clear. Thank you !
NeoPa 32,556
Expert Mod 16PB NeoPa:
Normally, such a situation is unacceptable, but there may be exceptions.
Lol :-D
So... It seems you must be a politician in real life Mihail. You should remember to quote things in context, otherwise, of course, it will say something quite different from what was actually said ;-)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: JT |
last post by:
is there a way to warn the user before their session expires??
|
by: Mark 123 |
last post by:
Hi
I am getting an Object Expected error when using the following script. Can
anyone see any syntax error?
<script>
aTemp=location.href.split("?");
|
by: Theresa Hancock via AccessMonster.com |
last post by:
I have an Excel table I need to import into Access. The name is entered into one field "Name". I'd like to have two fields in Access, FirstName and LastName. How do I do this.
--
Message posted...
|
by: markalroberts |
last post by:
Hi,
I wish to ask warn the user that there are unsaved changes (if there
are) and allow them to cancel navigating away/closing the browser.
Investigation leads me to believe the...
|
by: NH |
last post by:
How can I warn a user that their session has expired when they click on a
button etc?
|
by: itsnavigator |
last post by:
First of all, im not a pro on js, im trying to do something by using it.
I really wonder, is that possible to warn user without using window.focus ?
I just dont know the rigth word, i try to...
|
by: emanning |
last post by:
Using Access 2003 and using a form that's mostly bound. I need a way
to tell if user-1 is on the record when user-2 tries to open the same
record, w/o waiting for the user-1 to save the record...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: 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...
|
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...
| | |