0% found this document useful (0 votes)
132 views5 pages

Troubleshooting MS-Access Error 31532 - Unable To Export Data

The author describes troubleshooting an MS Access error that prevented exporting data. They narrowed it down to a field using Left() and InStr() functions to extract a date code from a shipment ID. On one record, InStr() returned -1, causing the error. Adding error handling to the custom function and validating data entry resolved the issue.

Uploaded by

tetkaC
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views5 pages

Troubleshooting MS-Access Error 31532 - Unable To Export Data

The author describes troubleshooting an MS Access error that prevented exporting data. They narrowed it down to a field using Left() and InStr() functions to extract a date code from a shipment ID. On one record, InStr() returned -1, causing the error. Adding error handling to the custom function and validating data entry resolved the issue.

Uploaded by

tetkaC
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

6/25/2020 Troubleshooting MS-Access Error 31532 - Unable to export data. | ComeauSoftware.

com

Comeau Software Solutions


Notes on programming, databases and other ways technology can work for you.

Troubleshooting MS-Access Error 31532 – Unable to


export data.
Microsoft Access can sometimes seem to have its own obstinate personality, throwing errors that persist no
matter what you try. I wanted to share a recent troubleshooting experience to show some of the steps that you
can take when a function is just not working as expected and the decision process involved in xing it.

The Problem

The other day, I received a bug report from one of my clients over e-mail. They were trying to run a report I’d
designed for them awhile back and getting a rather vague error.

At least the VBA error handler worked as designed; it passed along the error number and description that VBA
coughed up and allowed the user to exit from the screen and continue using the program. It wouldn’t hurt if I
had included the name of the subroutine for my own convenience but this client is good about providing
information on where they found it. In this case, it was a form that enables them to preview the results of a
query and then export it to Excel.

The Process

Investigating the procedure behind the form, I found the DoCmd.TransferSpreadsheet command where it was
failing and the query it was trying to export. Running the query, I got another error when trying to preview the
data instead of exporting it:

https://www.comeausoftware.com/2019/09/ms-access-error-31532-unable-to-export-data/ 1/5
6/25/2020 Troubleshooting MS-Access Error 31532 - Unable to export data. | ComeauSoftware.com

The “too complex to be evaluated” error in an Access query is a bit like the Check Engine light in your car. It’s
not going to tell you what’s wrong but there’s de nitely something Access SQL doesn’t like and it won’t
cooperate until you gure it out.

The next step was to look at the elements in the query to see what might have been causing the problem.
Removing all but a couple of basic elds enabled the query to run and this meant that at least the query itself
with its multiple table joins was working.

I nally narrowed it down to this eld:

This client uses a shipment reference number that combines a date code with a sequence number (-1, -2, -3,
etc..). On the rst line above, the query is using Left() and InStr() to strip o the dash and sequence number so
it can search the records just by the date code. The criteria line at the bottom shows that the resulting value is
being matched against a value selected from a combo box on the form. In this way, the client can pull all the
records for that date code.

Obviously, there was something in that combination of functions and criteria that was giving Access indigestion
but I needed it to work. I was also a little puzzled why it was failing now since I know I tested it before releasing
the changes to them.

Since Access wasn’t providing any more information, my next step was to break the Left() function down into
a custom VBA function of my own and use that in the query instead. In retrospect, I should have rst looked
more closely at the values that the Left() function was producing through the query but there are a lot of things
that seem obvious after they slap us in the face.

https://www.comeausoftware.com/2019/09/ms-access-error-31532-unable-to-export-data/ 2/5
6/25/2020 Troubleshooting MS-Access Error 31532 - Unable to export data. | ComeauSoftware.com

Public Function GetDateCodeFromShipment(ShipmentID As String) As String


'Get the position of the dash in the NonReturnID.
intDash = InStr([ShipmentID], "-") - 1
'Return the relevant portion.
GetDateCodeFromShipment = Left([ShipmentID], intDash)
...

I could then use this function in the query and it would return the date code needed to compare against the
one selected on the form.

… and it failed!!

The Cause

The routine was failing in the Left() function from last line of the code above That’s when I decided to look at
the values that the InStr() function was returning and, sure enough, I found that on one record, it was
returning a value of -1 which the Left() function didn’t like.

This was because, for the rst time in tens of thousands of records, the client had accidentally entered a
ShipmentID without the dash and sequence number. InStr() returned a 0 since it found no dash and then Left()
tried to select -1 characters from the ShipmentID, resulting in the illegal function call. Since the entire function
had been previously contained within the query, there was no error handling to explain the message until I
broke it out into my own function.

I also found that the query needed to be ltered on another eld that would further limit the records
returned. With the extra lter, the bad data didn’t even a ect it and it ran faster.

The Solution

The extra query lter was the rst step. Since I’d already written the new function, I decided to leave it in place
and added a couple lines to handle values that did not include the dash.

https://www.comeausoftware.com/2019/09/ms-access-error-31532-unable-to-export-data/ 3/5
6/25/2020 Troubleshooting MS-Access Error 31532 - Unable to export data. | ComeauSoftware.com

'Get the position of the dash in the ShipmentID.

intDash = InStr([ShipmentID], "-") - 1

'Return the relevant portion.


If intDash > 0 Then

GetDateCodeFromShipment = Left([ShipmentID], intDash)


Else

'No dash, return the whole thing.

GetDateCodeFromShipment = ShipmentID
End If

Then, I actually made this moot as I decided to try to prevent further data entry errors on the form where
the data had originally come from.

Private Sub ShipmentID_BeforeUpdate(Cancel As Integer)

...
'Verify there's a sequence number at the end.

If InStr(Me.ShipmentID, "-") = 0 Then


MsgBox "Shipment codes should end with a dash followed by a sequence number. (-1, -2, -3, etc..). Ple

vbOKOnly, "Missing sequence number ..."


End If

...

The BeforeUpdate event on a form eld can be used to run checks on the data and to cancel the update if
necessary. On the event declaration above, you will notice the Cancel argument. Setting this argument to True
(even though it’s an integer) will cancel the update and keep the focus on that eld until the user corrects the
problem. In this case, I decided just to show a warning and not restrict the client’s data entry any more than
absolutely necessary.

SUBSCRIBE TO BE NOTIFIED OF NEW POSTS …

You can stay up-to-date on new articles and resources from Comeau Software Solutions by subscribing to our
newsletter. You can opt-out at any time.
Email

Subscribe

https://www.comeausoftware.com/2019/09/ms-access-error-31532-unable-to-export-data/ 4/5
6/25/2020 Troubleshooting MS-Access Error 31532 - Unable to export data. | ComeauSoftware.com

This entry was posted in Microsoft Access, Programming on September 11, 2019
[https://www.comeausoftware.com/2019/09/ms-access-error-31532-unable-to-export-data/] by Andrew
Comeau.

1 thought on “Troubleshooting MS-Access Error 31532 – Unable to export data.”

David Nealey
November 2, 2019 at 1:32 pm

Thanks Andrew. I was considering using the same technique in my data and now I need to adapt your
technique to my database. My idea was to ask users to place numbers at the beginning of strings so users
would see associations if they existed. Today I plan to add thermometer charts to the module, which is
something altogether di erent.

Thanks again.

Comments are closed.

https://www.comeausoftware.com/2019/09/ms-access-error-31532-unable-to-export-data/ 5/5

You might also like