473,789 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

validate if entry is in the master table

30 New Member
How can I validate the entry in a form, say cutomer number, is in the masterlist table, else do not accept entry?
Dec 5 '07 #1
3 1436
OldBirdman
675 Contributor
One very simple way to answer many questions about your tables and entries within the tables is to create a ListBox (Example uses lbxWorkspace) on your form, and set .Visible = False. This becomes your test/workspace. Example is using a TextBox named txtEnter to enter the customer number.

Create a function, say IsValidEntry to use this workspace and validate the entry. Here I assume that the customer number must be numeric, and test for non-numeric entries before the query.
Expand|Select|Wrap|Line Numbers
  1. Private Function IsValidEntry(strEntryToValidate As String) As Boolean
  2.     If Trim(strEntryToValidate) = "" Then
  3.         'Entry is Blank[s]
  4.         IsValidEntry = False
  5.     ElseIf Not IsNumeric(strEntryToValidate) Then
  6.         'Entry is not Numeric
  7.         IsValidEntry = False
  8.     Else
  9.         'Entry meets conditions of Customer Number 
  10.         'Create SQL for Workspace
  11.         lbxWorkspace.RowSource = "SELECT Table1.Number " & _
  12.                 "FROM Table1 " & _
  13.                 "WHERE (((Table1.Number)=" & txtEnter.Text & "));"
  14.         If lbxWorkspace.ListCount = 0 Then
  15.             'ListBox is empty, therefore the Customer Number does not exist
  16.             IsValidEntry = False
  17.         Else
  18.             'ListBox is not empty, therefore the Customer Number is valid
  19.             IsValidEntry = True
  20.         End If
  21.     End If
  22. End Function
  23.  
  24. Private Sub txtEnter_Exit(Cancel As Integer)
  25.     Debug.Print IsValidEntry(Nz(txtEnter, ""))
  26. End Sub
  27.  
For test purposes, I'm using a TextBox named txtEnter to enter the Customer Number , and testing for validity On Exit. Testing On BeforeUpdate would also be appropriate, but if Customer Number doesn't exist, why wait to inform user?
Note that you could use the same workspace to count the number of orders by this customer in the last year, and offer discounts, etc.

I hope this helps.

OldBirdman
Dec 6 '07 #2
puppydogbuddy
1,923 Recognized Expert Top Contributor
How can I validate the entry in a form, say cutomer number, is in the masterlist table, else do not accept entry?
One way is to do a Count of records returned on a DLookup as shown below:

If Count(DLookup("[CustomerID]", "tblCustome r", "CustomerID = " & Me![CustomerID]) > 0 then
' customer exists - accept the entry
Else
' customer does not exist on the table - reject the entry
End If
Dec 6 '07 #3
ebo2006
30 New Member
Thank you guys for the help.
Dec 6 '07 #4

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

Similar topics

4
1548
by: Clara | last post by:
Hi, can somebody help me,..I have an assignment due next week but now I'm stuck with this problem.... I tried to get values from entry widget using the widgetcontrolvariable.get(),..but it seems that it won't work.... I can't print the value I input in the entry widget...However when I first set the value to something I can get the value just fine... This is my code Help please... msg='*~*Please Login to use the system*~*'
5
5430
by: lottaviano | last post by:
I am using Access 2002 and have two tables (Main and Actions) linked (in Relationships) on one field "CAL_ID" (primary key in Main Table). Main Table is a list of equipment. Actions Table lists actions performed on these pieces of equipment (calibration, cleaning, etc.) so there are many records per every one record in the Main Table. I have a form based on Main Table, containing a subform for Actions Table. This is used for data...
11
8196
by: TokyoJ | last post by:
I run a small camp in Alaska for kids and my director is asking for a web form. Could someone please have a look and offer some advice on where I'm making mistake(s)? I'm using the RegExp function to validate 3 types of fields: text, radio button, dropdown menu. but the code doesn't validate. After 2 days, it's time I asked for guidence. Criteria: Text: only alphabet, no numerals, allowed Radio: one must be selected, Dropdown: an option...
1
2808
by: NHNeedsHelp | last post by:
Hi, about to go nuts - I have a master form with 3 control buttons, user picks 1 for Const. job, 2 for Envir job and 3 for Geo job. Each button opens a subform containing the project number from master form. The subform is basically a data entry form with a couple of pull down selections for the user to choose. The choices made on the subform auto fill a field called "New Project No" - That new number is compiled from the user choices, like...
24
2111
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help automate and clean up parameter validation code. It's almost ready to go into open beta. But one last little glitch is holding me up, and that would be the name of the factory class that serves as the entry point into the library: Validate.
2
1532
by: spcscooter via AccessMonster.com | last post by:
I have a form that I have subforms in. I have set up relationships between all tables for cascading delete so that once I delete from the main table it should delete the entry that shares the relationship in the other tables as well. It's not. I know I am doing this wrong but I don't know what I am doing wrong to fix it. Please help.
3
1482
by: asit | last post by:
from Tkinter import * def callback(): print e.get() master=Tk() e=Entry(master) e.pack(anchor=CENTER)
1
1651
by: TC | last post by:
Hi, I have an app that is going to require recurring diary entries, it's a relatively simple app but I have no idea how to go about the recurring entry side of things. The functionality needs to be similar to outlook in the way the recurring entries work, but the system will be built around a MySql database and I don' want to add thousands of records, although each recurring entry could contain different information. Any ideas would...
0
9663
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10195
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.