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

validate if entry is in the master table

30
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 1420
OldBirdman
675 512MB
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 Expert 1GB
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]", "tblCustomer", "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
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
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...
5
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...
11
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...
1
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...
24
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...
2
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...
3
by: asit | last post by:
from Tkinter import * def callback(): print e.get() master=Tk() e=Entry(master) e.pack(anchor=CENTER)
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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,...
0
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...

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.