Solved

Excel - check whether data added to a SQL database

Posted on 2011-09-11
2
214 Views
Last Modified: 2012-05-12
Hi

In VBA I have written code to add data to an Access database.
I have code that checks the highest ID before and after the Insert Statement
and if this has changed returns a successful entry.
With multiple users however, this might cause problems.
Should I maybe also use a select statement to see if that exact info is there?
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 36518433
If you cannot use an alternative like method I showed with SCOPE_IDENTITY(), then you may need to do something like that to be absolutely certain. For example, you may check for MAX(ID) and 100, then execute an insert that fails, but check for MAX(ID) again which returns 101 as another process successfully inserted a new row. As an alternative, you could run a scalar query that tests EXISTS() or COUNT() ... WHERE based on your criteria; however, if the insert failed because there was already a row with your new data then this method may also be flawed.

You may have to use a stored procedure to do inserts where you can return true or false to indicate success or failure.
0
 

Author Closing Comment

by:Murray Brown
ID: 36518880
Thanks very much
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question