473,395 Members | 2,423 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,395 software developers and data experts.

Check if PartNumber (calculated) already exists

Dear,

I store PartNumbers in a table called PartT. these Partnumbers are calculated from different fields (ex: EBAPOL-M25-00024-02)(system=M / XX_Number = 25 / Sequence = 00024 / Subsequence=02). All the different fields need to be filled in a form for new records.

I would like Access to check, after the information is filled in, whether the (caculated) partnumber already exists in the PartT table.

I created a button that saves the new reccord and I tried to at a Macro "Dcount()":

Expand|Select|Wrap|Line Numbers
  1. If
  2.  DCount("PartNumber";"[PartT]";"PartNumber= '" & [Formulieren]![NewPartF]![PartNumber])>0
  3. Then MsgBox(PartNumber already exists)
  4. End If
  5.  
But after testing and trying to add a existing Partnumber, No Msgbox shows up.

Can you help me?

Thanks!
Nov 12 '15 #1
2 1007
zmbd
5,501 Expert Mod 4TB
Your code as is - but stepped
Expand|Select|Wrap|Line Numbers
  1. If
  2.   DCount("PartNumber"; _
  3.     "[PartT]";
  4.     "PartNumber= '" & _
  5.         [Formulieren]![NewPartF]![PartNumber])
  6.      >0
  7.  Then 
  8.     MsgBox(PartNumber already exists)
  9.  End If 
Honestly, I am surprised this didn't toss all sorts of compiler errors - it should have, if not, then we need to know what programing language you are using.

Ok, to pull this apart more:

Is [PartNumber] numeric or text?

If text then you need to close the string thus: " ' ":
Expand|Select|Wrap|Line Numbers
  1. "PartNumber= '" & _
  2.     [Formulieren]![NewPartF]![PartNumber] & _
  3.        "'"
If numeric only, then remove the " ' " from the line
Expand|Select|Wrap|Line Numbers
  1. "PartNumber= " & _
  2.     [Formulieren]![NewPartF]![PartNumber]
Next the semicolon is not used in this function, thus you should have for text:

Expand|Select|Wrap|Line Numbers
  1. DCount("PartNumber", _
  2.     "[PartT]", 
  3.     "PartNumber= '" & _
  4.         [Formulieren]![NewPartF]![PartNumber]) & _
  5.        "'"
Finally, I highly advise that you build your criteria string first:

Expand|Select|Wrap|Line Numbers
  1. '(...other code...)
  2. DIM zWHERE as String
  3. '(...other code...)
  4. zWHERE = "PartNumber= '" & _
  5.     [Formulieren]![NewPartF]![PartNumber] & _
  6.        "'"
  7. '
  8. DCount("PartNumber", _
  9.     "[PartT]", _
  10.     zWHERE)
  11.  
  12. '(...other code...)
Finally the comparator (>) need not be used. If DCOUNT() returns anything except an error or zero, the true condition will be satisfied.

Next
Expand|Select|Wrap|Line Numbers
  1. MsgBox(PartNumber already exists)
Is not the correct syntax.

Try:
Expand|Select|Wrap|Line Numbers
  1. MsgBox "PartNumber already exists"
If you have the OPTION EXPLICIT set it's a simple catch to run the debug/compiler to find these types of syntax errors.

Finally, it could be that your domain function is also returning zero; however, I don't think the runtime reached that point.

If you will correct your code and repost we can tweak it more from that point.

:)
Nov 12 '15 #2
Thanks A lot zmbd! The new code works!
Nov 13 '15 #3

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

Similar topics

6
by: Chad Crowder | last post by:
Getting the following error on my production server whether the file exists or not: "System.IO.IOException: Cannot create a file when that file already exists." Here's the code generating the...
9
by: Carl Fenley | last post by:
I am successfully adding stored procedures to an Access database. However, I need to be able to check if the stored procedure of the same name already exists. Is there a way to do this other...
14
by: John Salerno | last post by:
What is the best way to check if a file already exists in the current directory? I saw os.path.isfile(), but I'm not sure if that does more than what I need. I just want to check if a file of a...
3
by: byeung | last post by:
Hi, I am trying to check if a particular record already exists in an Access database through Excel vba code. Through code obtained at another forum, I got the following: ...
59
oll3i
by: oll3i | last post by:
how to check if an object already exists and return reference to that object
4
gundarap
by: gundarap | last post by:
Hello all, I'm working on minidom. My goal is to see whether an element already exists in the xml file before adding. I was using getElementsByTagName() to check weather the element already exists....
5
by: ashurack | last post by:
I found a stored procedure online a while back and want to inplement it. The only problem is that it doesn't check to see if the number generated is currently in use in the DB. I know it's really...
0
by: bharathreddy | last post by:
This article will explain you how to check weather a column already exists in a table before you add the column to the table using alter command. Using the system tables...
1
by: michaeldebruin | last post by:
I am trying to create an application which acts a bit like a database. But I need help with the saving function, because after I wrote a name in the application it first needs to check if the name...
3
by: PetroTiburcio | last post by:
I have this table Profile which has fields with user_Id and regNo and I want to check first if id and email are already exists before proceed to inserting datas. In my codes, I am able to validate...
0
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...
1
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...
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
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
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
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,...

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.