Access frontend with SQL Server backend: my solution for ODBC Call error


This thread follows threads I started in forums 
microsoft.public.access.forms, and microsoft.sqlserver.programming:
1. 'Overriding constraint violation message' at 21.04.2010 12:00;
2. 'Overriding constraint restriction message, when deleting record(s) from 
form' at 29.04.2010 10:36.

The problem (Occurs in Access 2000 mdb as stated by MS and in Access 2007 
mdb as I myself discovered):
When record operation is aborted from SQL Server, Access gets the full 
information about error, but this info gets unaccessible at moment when 
OnError event is triggered. The standard error message is messy, and 
confusing for user.

My solution:
In Access standard module I have a function:

Public Function WasODBCError(DataErr As Integer, WasDirty As Boolean, WasNew 
As Boolean) As Boolean
    If DataErr = 3146 Then
        ' An ODBC Call error occurred.
        If WasDirty And WasNew Then
            ' Entering of a new record was interrupted.
            ' Possible causes:
            ' 1) Primary key violation;
            ' 2) Unique key violation.
            MsgBox "The record, you tried to add, wasn't saved," & vbCrLf & 
"because you tried to repeat an unique value or an unique combination of 
        ElseIf WasDirty Then
            ' Editing of an existing record was interrupted.
            ' Possible causes:
            ' 1) Primary key violation;
            ' 2) Unique key violation.
            MsgBox "Changes weren't saved," & vbCrLf & "because you tried to 
repeat an unique value or an unique combination of values!"
            ' A record deletion was tried.
            ' Possible causes:
            ' 1) Foreign key violation.
            MsgBox "The record wasn't deleted," & vbCrLf & "because it was 
linked to records in other tables!"
        End If
        WasODBCError = True
        WasODBCError = False
    End If

End Function

For every form/subform which has an ODBC datasource, I have a.n OnError 

Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Response = IIf(WasODBCError(DataErr, Me.Dirty, Me.NewRecord), 
acDataErrContinue, Response)
End Sub

Some explanations:

With one exception all Primary keys in my tables (and referred in remarks 
for function WasODBCError) are based on single numeric Identity column. Most 
of tables have additionally one unique key, which is based on one text 
column in same table and optionally on a foreign key column.
An Example with a couple of tables:
tblAreas (Fields: AreaID Numeric(18,0) IDENTITY, AreaName Varcher(20), ... , 
Keys: PK=AreaID, UK=AreaName)
tblBuildings (Fields: BuildingID numeric(18,0) IDENTITY, AreaID 
numeric(18,0), BuildingName varchar(30), ... , Keys: PK=BuildingID,  UK = 
BuildingName+AreaID, FK=AreaID>tblAreas.AreaID)

I scrapped my solution from thread 'Overriding constraint restriction 
message, when deleting record(s) from form', and a MS solution from;en-us;206175, because:
1. Too much glogal variables and code to manage for my taste - especially 
considering that I have 9 subforms on my Main form currently;
2. In MS solution were 2 bugs. The first one made impossible to edit later 
fields, which were left blank originally (and probably to clear nonblank 
fields later too), and was easy to mend. The second was caused with attempt 
in BeforeUpdate event to move to last record when a new record was added, 
and I did foresee, that the only working solution will be another set of 
global variables and another portion of code in BeforeUpdate and Current 
events for every subform. It was TOO MUCH!

PS. When you look at MS solution for adding/updating closely, then you see 
that they have WRONG HEADER for this article! The article is about ONERROR 
event, but the header speaks about ONOPEN event :-))  I don't think there 
are many of people, who did find this article purpousely.

Albeit MS solution wasn't good enough, it helped me immensely to understand 
the situation better. Thanks to Stefan for pointing it out to me.

Arvi Laanemets 

5/7/2010 10:35:24 AM
access 16762 articles. 3 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 25

hi Arvi,

> My solution:  [..]
Cool, nice piece of work.

--> stefan <--
5/7/2010 12:12:56 PM

Similar Artilces:

Restricting access to note attachments
Hi all, is there a way to restrict access to attachments on notes to specified users. I know we can, using the Security Roles, define who can and can't read/ write the notes fields but we would like our users to be able to view the note, but not open the attachment(s) unless they are the owner of that note (or at least in the business unit, etc.). I know this could be done for Word/ Excel files in Office (Password protection) but are looking for something more encompassing for all attachments inside CRM. Thanks, -- Matt Pring On Oct 21, 3:54=A0pm, Matt Pring <MattPr...@discus...

Outlook Web Access AutoSignature
I would like to know if it's possible to have autosignature in Outlook Web Access, and if so how to implement it. If anyone can help, it would be greatly apreciated. Thank You. It depends on the version of Exchange - Outlook Web Access is a function of Exchange, not Outlook. Exchange 2003 does this natively, previous versions may have a third party add-in that will allow users to do this. For better information, post in an exchange group such as --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due t...

"Unexpected Error" When Sending CRM E-Mail
We are getting an "Unexpected Error" when sending CRM E-mail from both Outlook and the web client. There is no diagnostic message. The following appears in the Event Viewer for the web client: Event Type: Error Event Source: Microsoft CRM Event Category: None Event ID: 2 Date: 2/10/2005 Time: 1:42:23 PM User: N/A Computer: BHE-SHARE Description: MSCRM Platform Error Report -------------------------------------------------------------------------------------------------------- Error: <description>An unexpected error occurred.</description><details>An error occ...

RPC over HTTPS only + Encrypt data between Outlook and Exchange server Option
I need to clarify the difference between having only RPC over HTTPS setup and working fine.... and adding the option in outlook 2003 to Encrypt data between Outlook and Exchange server Option what i need to know is: 1) what is gained in adding this option? 2) without adding this option what is the security issue? ...

ADO/SQL Server: datetime column appears to be "1901-1-1 00:00:00" after insertion
Hi. I'm using ADO connection and recordset to insert records from Table1 to table2. The database is SQL Server 2005 and the connection is established before the following the code snippet with "csvSQL". The code works without any error but the result is not what i want. The issue is that when aTIME1 is "" and is inserted to table2, TIME1 of Table2 becomes "1901-1-1 00:00:00". FYI, TIME1 is of type datetime and allow null. What i expect is when aTIME1 is "" and inserted to Table2, TIME1 should be null. Please help. Thanks. Set csvR...

Is it possible to install two CRM Servers in the same domain using a single Exchange Server? It will work four outbound email, but even with the v3.0 router changes, I do not know if it will work for inbound email. Probably need to check with support on this for sure. -- Matt Parks MVP - Microsoft CRM "Irshard" <> wrote in message Is it possible to install two CRM Servers in the same domain using a single Exchange Server? yes it is. NOTE: This is already assuming you have two...

Access 2003 and Access 2007 Synchronization
I'm setting up a new business relationship with a company in Portugal. They use Access 2003. I have just bought MS Office Professional 2007 (with Access 2007). Our plan is that they will send, once a month or so, their Access db then we will update and add to that db and then return it after another month or so. There probably won't be a lot of updates on our end so the monthly cycle should work. After they synchronize, they will send a new version of the db and we will start over. My goal is to keep everything as simple as possible partially because I don't know how skillf...

using paid servers with Outlook Express.
I've been using, a free text server with Outlook Express. Does giganews work with Outlook Express? Can Outlook Express deal with binary newsgroups? Should I use a different news program like Forte Agent? I have a very old version of Forte Agent, but I like having my newsgroups right there by my email. Oops. I should have posted to microsoft.public.outlookexpress ...

Calculation Error in Money 2004 Small Business
When you enter 80*51.875 as expense in a bank account for example, the result correctly shows as 4150. However, if you go to Invoice and enter 80hours @ $51.875, it shows 4150.40 - Calculation bug? MS Online Assisted support confirmed the problem. They also found that if you enter the numbers in reverse i.e 51.875h @ $80, it correctly shows 4150. So it looks like Money 2004 erroneously rounds off the per hour labor rate to two decimal digits 80*51.88 = 4150.40). >-----Original Message----- >When you enter 80*51.875 as expense in a bank account for >example, the result corre...

Excel Row to Access Columns
Hi, I have a single row in Excel with a lot of data, what I need to do is move that to a column in Access. I need some way to automate that. I know the easiest way to do that would to just transpose it in excel and then import in access.But I cant do that as I just get that excel file with one row and I need some way to automate the process in Access. thanks m -- mk389 ------------------------------------------------------------------------ mk389's Profile: View this thread:

Help displaying a random record in a form--Access newbie
Hello, I am new to Access, so if anyone can help me, please assume I know absolutely nothing! I currently have a table with two columns, ID and CHORE. In each row, the ID number corresponds to a chore that I have entered. I would like to create a form with a button and a text field such that when I press the button, a random chore is displayed in the text field (supposed to make chores more "fun" for my son). There is no need to remove this record from future clicks (the same record can come up over and over without any problem for me) Can anyone explain to me (in pai...

HELP: VBScript to detect error messages in excel VBA
I wish to use vbscript to automate macros running over many workbooks. I will allow a number to run at any given time, therefore i need to use vbscript to detect if a macro has ended. This is not posing an issue. The issue I foresee is if the macro being run in the excel book decides to error (maybe because an SQL server is down, or any reason really)... I need the ability to have vbscript work out that the runtime error has occurred in the excel workbook, kill the application, then re-launch the workbook to allow the maco a second run. Essentially, how will i use vbscript to...

Hi My form takes a few moments to load up as it is fairly substantial SQL statement is there a way to get something to display a graphic or 'loading...' message to appear why it calculate the contents? Steve ...

Excel, ODBC and creating queries
Does anyone know of a way to create a query based on values or formula in a spreadsheeet? Thanks in advance, J -- Message posted from From reading between the lines of your post, I am guessing that you have an Access Database with which you want to create a query based on a spreadsheet. If this is the case, you will need to open your database and in the tables section of your databse , right mouse click in the area showing your table names, and select "Link Tables" from the menu. Once you have followed the rest of the steps in the link wizard, a...

Error 8007007E when doing Send and Recieve
preface: I have seen a few posts about this already, but none of them have worked for me because (a) my system is locked down by my IT department and adding Outlook Express is not possible, or (b) the suggested fix made no difference My problem is this - I have recently been given Outlook 2003 (finally!) to test out connectivity to our Domino back end. Things did not go well as Outlook would just randomly shut down somewhere in the middle of downloading the data. In an attempt to see if it was Domino, the connector or Outlook, I tried wirind up Outlook to my Yahoo!, Hotmail and AOL email a...

Moving contacts to Exchange 2000 Enterprise Server
Does anyone know an easy way to move my smtp addresses from CCmail 8.2 address book (about 400 of them) over to contacts in Active directory. I am running Windows 2000 Server and Exchange 2000 Enterprise Server. Cheers Crazy cc:Mail's export command with the /DIRECTORY switch can export them in an quasi - ldif format which could be massaged and used with ldifde to import. cc:Mail's Import/Export users guide will help on the export start with 237677 Using LDIFDE to import and export directory objects to Active Directory;EN-US;...

Import Wizard Error
We're trying to import leads from a tradeshow into MSCRM 1.2. I utilize the Import Wizard, find the source .csv, map the fields (and ensure none of them are blank), and press import. I receive the error: "A system error occurred while the data was being imported. The Import Wizard will now close." Any help would be greatly appreciated! Kind Regards, Anthony Uliano President/CTO AMC Technology, L.L.C. is your crm web server running on a port other than port 80 ? -- John O'Donnell Microsoft CRM MVP "Anth...

access mail on WEB
Is there a way i can check emails from exchanger server 5.5 from an internet browser. I have Exchange 5.5 in win NT 4.0. Thanks! Yes - install OWA (Outlook Web Access) and open up the needed ports in your firewall (80 for http; better to use SSL and port 443 instead). disk0nek wrote: > Is there a way i can check emails from exchanger server > 5.5 from an internet browser. > > I have Exchange 5.5 in win NT 4.0. > > Thanks! ...

access or mount mirrored hard disks
Hi, is it possible to access a mirrored harddrive? or mount the mirrored volume by using api or mfc commands? Thank you in advance Wimpi ...

2nd Post: DATEVALUE Error
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Hello, <br> I need to manipulate some date/time strings that I'm importing from an external source. The dates are DEFINITELY in text format, and are not in date (serial number) format. <br><br>The strings look like this: <br><br>10/30/2009 3:19:08 PM <br><br>I need to separate date &amp; time, and use subtotals etc. on change of date &amp; change of hour. <br><br>I thought the best thing would be to separately extract the date and time, then use ...

SMTP server #2
I have a basic question on SMTP emails. If I point to a SMTP server that is different than my designated email host address, who actually sends out the emails, my designated email server or the one I pointed to? To help clarify we have our email and web hosted by a 3rd party Company "A", and my ISP is with Company "B", I have been having problems with duplicate emails being sent to several clients. So I pointed my outbout emails to a different SMTP server (Company B's smtp server) in an attempt to see if the problem goes away. So I am check to see if my...

CRM v4 Accessibility Improvements
Hi all: Does anyone know if any improvements have been med to CRM v4 in the area of accessibility for handicapped users? One of my customers has a user who is blind and they need to make the software accessible to him. Thanks in advance for any and all help. John. Hi John, We have added following Accessibility features in CRM 4.0 : 1) High Contrast Mode (Tools --> Options --> General Tab --> Enable high contrast settings) 2) All the Form input elements have <LABEL FOR> to aid in screen readers. 3) All the Images have a ALT tag (for non text elements) etc. Thanks! Ma...

Access Database In Great Plains
I was wondering if anyone knew how to have the databases that are stored in access transfered over to great plains. I'm current running version 8.0 any help would be greatful. thanks Search Customer Source for integration Manager. MS Access databases can be used as a data source. Vincev "jake" wrote: > I was wondering if anyone knew how to have the databases that are > stored in access transfered over to great plains. I'm current running > version 8.0 any help would be greatful. thanks > > Hi Jake, Is this something you need to do regularly or is it ...

Upsizing Access to SQL Server 2000
Hello, I am new to SQL Server. I am trying to use the Database upsizing wizard to upsize a Access 2000 database into SQL Server 2000. They are both on the same machine (running Win 03 Server). I cannot connect to the SQL Server. Error as below: Connection failed: SQLState: '01000' SQL Server Error: 14 [Microsoft][ODBC SQL Server Driver][Shared Memory] ConnectionOpen(Invalid Instance()). SQLState: '08001' SQL Server Error: 14 [Microsoft][ODBC SQL Server Driver][Shared Memory]Invalid connection. ...

Outlook Web Access #19
We have have OWA at my work and I would like to configure Outlook 2003 to synchronize with my desktop at work, is this possible Thanks B ...