Troubleshooting MS-Access Error 31532 - Unable To Export Data
Troubleshooting MS-Access Error 31532 - Unable To Export Data
com
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.
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
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
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.
...
'Verify there's a sequence number at the end.
...
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.
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.
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.
https://www.comeausoftware.com/2019/09/ms-access-error-31532-unable-to-export-data/ 5/5