473,396 Members | 1,895 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,396 software developers and data experts.

If data exists then run query

Hi,

I am using Access 2007.

I have a simple table with 2 fields [Case] and [Target]
My form has a list box populated with Case Types, a text box for the user to input the Target number for the selected Case and a button that i need to run queries to update the table on click.

The table could start blank and i don't want any duplicates, so the 2 queries i think i need to run are:
1. To check if a certain Case exists and if so update the Target with what the user has input.
2 If the Case doesn't already have a target to update, the new Case and Target need to be inserted.

I'm running them from VB as:

DoCmd.RunSQL "UPDATE CaseTarget SET [Target] = ('" & Forms!MainMenu!CTargetText & "') WHERE [Case] = ('" & Forms!MainMenu!CallList & "');"

DoCmd.RunSQL "INSERT INTO CaseTarget (Case, Target) VALUES (('" & Forms!MainMenu!CallList & "'), ('" & Forms!MainMenu!CTargetText & "'));"

But how do i say if there is no Case to Update, then Insert?

Thanks

Chris
Feb 25 '08 #1
3 2340
FishVal
2,653 Expert 2GB
Hi, Chris.

You may just set a unique index on field [Case] and run these two queries sequentially. If you sandwich the code between
Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings False
  2. .......
  3. DoCmd.SetWarnings True
  4.  
then you will not receive message " ... record(s) was/were not added due to index violation" - the second command will just fail silently if a value you try to write to [Case] field is a duplicate.

Regards,
Fish.
Feb 25 '08 #2
Hi, Chris.

You may just set a unique index on field [Case] and run these two queries sequentially. If you sandwich the code between
Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings False
  2. .......
  3. DoCmd.SetWarnings True
  4.  
then you will not receive message " ... record(s) was/were not added due to index violation" - the second command will just fail silently if a value you try to write to [Case] field is a duplicate.

Regards,
Fish.

Thats worked great, thank you!
I have another related problem now but i'll make a new post!

Chris
Feb 25 '08 #3
NeoPa
32,556 Expert Mod 16PB
This may be off-base, but why not let Access handle this automatically for you in a form created by the Form-Wizard?
Feb 26 '08 #4

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

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
8
by: Frnak McKenney | last post by:
Back when computer dinosaurs roamed the earth and the precursors to today's Internet were tiny flocks of TDMs living symbiotically with the silicon giants, tracking access to data processing...
2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
4
by: jeff brubaker | last post by:
Hello, Currently we have a database, and it is our desire for it to be able to store millions of records. The data in the table can be divided up by client, and it stores nothing but about 7...
4
by: teddysnips | last post by:
My application is to capture employee locations. Whenever an employee arrives at a location (whether it is arriving for work, or at one of the company's other sites) they scan the barcode on...
0
by: Stephen | last post by:
Hi, Suppose I have 2 tables. TableA has about 3 million rows and TableB has about 50,000 rows. Assuming a btree index is used in the time column. I need to query a limited and time ordered...
5
by: Chris | last post by:
I have a meetings section I'm developing on our intranet. Using PHP/MySQL. Meeting info and Meeting docs reside on 2 related tables in the db. Users may want to upload anywhere from 1 to 10 or...
0
by: kucol | last post by:
Hi guys, I wanted to ask you for help as I am struggling with it second evening already... I have got tables DEVICES and PARTS. One device can consist of multiple parts. But... I have...
5
by: yuva17raj | last post by:
hi i am trying to update my sql table data with the csv/excel file data my sql table is as follows test test1 23 usd 25 ero 34 test and my csv file has
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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.