How can I validate the entry in a form, say cutomer number, is in the masterlist table, else do not accept entry?
3 1436
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. -
Private Function IsValidEntry(strEntryToValidate As String) As Boolean
-
If Trim(strEntryToValidate) = "" Then
-
'Entry is Blank[s]
-
IsValidEntry = False
-
ElseIf Not IsNumeric(strEntryToValidate) Then
-
'Entry is not Numeric
-
IsValidEntry = False
-
Else
-
'Entry meets conditions of Customer Number
-
'Create SQL for Workspace
-
lbxWorkspace.RowSource = "SELECT Table1.Number " & _
-
"FROM Table1 " & _
-
"WHERE (((Table1.Number)=" & txtEnter.Text & "));"
-
If lbxWorkspace.ListCount = 0 Then
-
'ListBox is empty, therefore the Customer Number does not exist
-
IsValidEntry = False
-
Else
-
'ListBox is not empty, therefore the Customer Number is valid
-
IsValidEntry = True
-
End If
-
End If
-
End Function
-
-
Private Sub txtEnter_Exit(Cancel As Integer)
-
Debug.Print IsValidEntry(Nz(txtEnter, ""))
-
End Sub
-
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
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
Thank you guys for the help.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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*~*'
|
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...
|
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...
|
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...
|
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.
| |
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.
|
by: asit |
last post by:
from Tkinter import *
def callback():
print e.get()
master=Tk()
e=Entry(master)
e.pack(anchor=CENTER)
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |