473,548 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB code to perform custom query of MS access table and display alert

I have a MS access database which has entries (each of which has a name
field) and uses a form to make new entries. I would like to put
together code that will run when a new entry's name is entered that
does the following:

1) query the database to see if that name is already entered
2) if the name is already present, popup a msgbox telling the user the
name is already in the system, and in some way list the results of the
query (it is possible to have more than 1 record in the table to have
the same name)

I think I can do part 1 by running VB code that runs as afterupdate
event code, but I'm having trouble finding out how to connect to the
access database and perform the query.

Any help would be greatly appreciated.

George Hadley
gh********@yaho o.com

Dec 26 '05 #1
4 1922
On 26 Dec 2005 12:32:31 -0800, gh********@yaho o.com wrote:

A column name of "name" is discouraged, because it is a reserved word.
Use it at your peril. Below I'm assuming you renamed it to
CustomerName, that the name of your control is txtCustomerName , and
the name of the table in question tblYourTable.

A crude way of doing what you want is to place the following code in
the CustomerName_Af terUpdate event:
dim lngCount as Long
lngCount = DCount("[CustomerName]","tblYourTable ","[CustomerName]='" &
txtCustomerName & "'")
if lngCount > 0 then
Msgbox "There are already " & lngCount & " customers by that name in
the database.", vbExclamation
else
Msgbox "Cool - New name.",vbExclam ation
end if

A more elegant approach requires the use of a recordset, concatenating
the records with the same name. That's a bit more advanced. See this
link for details:
http://www.mvps.org/access/modules/mdl0004.htm

-Tom.
I have a MS access database which has entries (each of which has a name
field) and uses a form to make new entries. I would like to put
together code that will run when a new entry's name is entered that
does the following:

1) query the database to see if that name is already entered
2) if the name is already present, popup a msgbox telling the user the
name is already in the system, and in some way list the results of the
query (it is possible to have more than 1 record in the table to have
the same name)

I think I can do part 1 by running VB code that runs as afterupdate
event code, but I'm having trouble finding out how to connect to the
access database and perform the query.

Any help would be greatly appreciated.

George Hadley
gh********@yah oo.com


Dec 27 '05 #2
George:

Actually, I would use the BeforeUpdate event, rather than the
AfterUpdate event. Otherwise, you'll ALWAYS have an entry that matches
the one you just input because the record has already been added. :)

Jana

Dec 27 '05 #3
On 27 Dec 2005 08:47:06 -0800, "Jana" <Ba********@gma il.com> wrote:

I was assuming the form would have more fields than a single
CustomerName field. If that's correct, then CustomerName_Af terUpdate
is the best event to put this code, unless you want to whistle back
the user and deny the right to add a duplicate (which is not what the
OP indicated).
If there are several more fields in addition to CustomerName, just
filling out that field does NOT create the record in the table.

-Tom.

George:

Actually, I would use the BeforeUpdate event, rather than the
AfterUpdate event. Otherwise, you'll ALWAYS have an entry that matches
the one you just input because the record has already been added. :)

Jana


Dec 28 '05 #4
Thank you for all the replies. The code appears to work properly as an
AfterUpdate event. The table does in fact have more than the
CustomerName field.

Is it possible to modify this code to take into account information
from another field?

In other words, do a count of customer name where a particular criteria
exists? e.g. [AcType=4]

Thanks,

George

gh********@yaho o.com

Dec 30 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6144
by: Shufen | last post by:
Hi, I'm a newbie that just started to learn python, html and etc. I have some questions to ask and hope that someone can help me on. I'm trying to code a python script (with HTML) to get values from a html form that consists of about 10 checkbox and a textbox where user have to key in a value to perform a search. From python tutors, I...
8
3199
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled 'search' may be clicked on by the user and the user can then search all records by postcode. I want to do this to prevent duplicate data entry.
18
18328
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
11
4969
by: trinitypete | last post by:
Hi all, I have a user control that uses control literal to build a heading with a link, and a div containing links below. As the link heading is hit, I want to change the style of the div, making it visible or not. Yep you guessed it, expanding tree type functionality. The header has an onclick event onclick='Doexpandcollapse
2
7967
by: Greg Strong | last post by:
Hello All, Is it possible to change table field lookup properties in code? I've been able to change other field properties in code, however so far no luck with field lookup properties. What I've done for test purposes is use a text input file for the table field lookup properties. I thought that I'd start first by just changing the...
3
2926
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news groups for years, I figure it's time for me to contribute a little bit back, maybe some people out there will find this useful. * Introduction ...
0
850
by: rn5a | last post by:
When a user finally confirms his order in a shopping cart application (using MS-Access as the backend), the items he has purchased are populated in a Access DB table named *Orders* & his personal details (like name, e-mail, billing address, shipping address etc.) are populated in another table named *CustDetails*. Both the DB tables have a...
9
5275
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from http://blogs.crankygoblin.com/blogs/geoff.appleby/pages/50712.aspx. I've also read the post on this topic by bggraphics, but he doesn't arrive at a final result. The main problem I...
10
2749
by: mukeshrasm | last post by:
Hi the code written below is for calculating the number of days remain for a particular event based on the specific local time i.e. time in new york or time in london. <style style="text/css"> .lcdstyle{ /*Example CSS to create LCD countdown look*/ background-color:black; color:lime; font: bold 18px MS Sans Serif;
0
7444
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7711
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7954
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...
0
7805
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...
1
5367
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...
0
5085
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3497
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...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1054
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.