Solved

Test whether a name already exists

Posted on 2014-01-28
4
340 Views
Last Modified: 2014-01-28
I have a form with a textbox "Blockname" which is bound to a field "Block" in table "tblBlocks".
Block is supposed to be a unique name.
When I fill in a new "Block", before I commence filling in other applicable data, I want a warning like "This name already exists. You need to enter a uniqe name or press "Escape" to exit."
I will probably use a "before update" action. Is that right?
What does the VBA look like that tests if the name already exists?
Thanks.
0
Comment
Question by:Fritz Paul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39814594
Before Update code would look like this:

IF DCount("*","tblBlock", "BlockName = '" & Me.txtBlock & "'") > 0 then
      msgbox  "This name already exists. You need to enter a uniqe name or press 'Escape' to exit."
      Cancel = True
      Me.txtBlock.Undo
End IF

Open in new window

0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 39814595
Hi,

Maybe by using a validation rule with Isnull(Dlookup()) otr DCount() in your table

Regards
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39814597
The above is assuming that Block is a text field.  If it is numeric, you would omit the single quote delimiters:

IF DCount("*","tblBlock", "BlockName = " & Me.txtBlock ) > 0 then
      msgbox  "This name already exists. You need to enter a unique name or press 'Escape' to exit."
      Cancel = True
      Me.txtBlock.Undo
End IF

Open in new window

0
 

Author Closing Comment

by:Fritz Paul
ID: 39814626
Thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question