Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

import spreadsheet issue from form button = table locked

Status
Not open for further replies.

merlizbet

Technical User
Oct 4, 2012
36
US
I finally figured out the issue and have come up with a work around, but I'm hoping someone here has a less klugie solution.

I normally link to spreadsheets, not import them, but starting with a test spreadhsheet pre-filled by the user, I found some bad data (a period only (.) entered into a cell in a numbers column and a space (" ") used to delete a number in a cell instead of the Delete key in a numbers column). The showed up in the linked Access table as #NUM! and I was trying to find a way to trap these errors in Access and present them to the user, but I could never search out a successful way to do that (ISERROR didn't work). Basically, I found most Google results ultimately saying to import the data as text first and then operate on it from there.

So, I imported the data and worked on it as text and can find the errors and present them to the user on a form. I say on the form to open the spreadsheet, make the corrections, and then return to this form and click the "Reset Data" button. In the "Reset Data" On Click event, I was simply trying to open a "wait" form, close the "errors" form, reimport the spreadsheet using RunSavedImportExport, and then re-run through the routine to check for errors. That all *seemed* to work until I realized the import was not actually happening.

After quite a bit of Google searching, I tried (1) recreating the SavedImport spec and (2) using a SavedImport to append rather than replace the existing table. Try #1 did not work any better and try #2 would not import a large amount of the data due to "Type Conversion Error" because I couldn't find a way to indicate the import spec field types in the Append method. But, what I did figure out was that, with the RunSavedImportExport in the autoexec macro, the import *did* work when the application first opened. Hm.

I thought maybe RunSavedImportExport would work if I deleted the existing table first, so I did a lot of Google searching to find out how to delete a table. Here's where the light bulb really came on. When I ran the procedure to delete the table, I got an MS error message saying the table couldn't be locked because it was already in use. Really? I don't have the table open and the first thing I did in my VBA procedure was to close the form. Hm. So, when I stepped though the procedure, what appeared to be happening was that even though I had closed the form, because I was initiating the procedure from a button on the form, the form was never really fully closing (or at least the table associated with the query providing the data to the form was never really released) until the procedure had tried to perform *all* the steps and finally returned to "End Sub" of the "Reset Data" button procedure.

With that in mind, I tried only closing the "error" form and opening the "wait" form from the "Reset Data" on the "error" form, and then putting the rest of the steps in the On Open event of the "wait" form. Still it won't let loose of the import table. So, I finally just did the open "wait" form and close "error" form from the "Reset Data" button (renaming it to "Initialize Data Reset") on the "error" form; then I added a button on the "wait" form to "Complete Reset". By fully ending any action that got initiated from the "error" form, the import table seems to be released/unlocked so that the RunSaveImportExport actually will perform the import. But it certainly seems klugie to me that I would have to make the user click 2 separate buttons on 2 separate forms to get this thing to work, so I'm hoping maybe somebody here has a prettier solution (that's not overly complicated).

Thanks for any ideas/suggestions.

 
Have you tried putting your code in a module and calling the procedure from a form's click event to close it. Personally I'd have it take the name of the form as a parameter so I could close it and would always call it with the paramater as Me.Name... that way it will easily work from any form (you might also only close if there is a value in case you want to call it from a form not bound to your data...)
 
How are ya merlizbet . . .

Your having a problem with program flow. And all seems to fall apart after you open the [blue]Error Form![/blue] and click on the So called Reset button ... How to circumvent actions of the Error form are in the forefront. A big part of the sequence needs to be called (at will) from standard modules (modules in the modules window). They would include:
[ol][li]Clearing the import table.[/li]
[li]Importing the Data from the SpreadSheet.[/li]
[li]Taging errors ...(however its done)[/li]
[li]Opening the Error Form for display.[/li][/ol]
My point is in the last step above. Note: if you determine the error form is already open ... [blue]you can simply requery the form![/blue] ... instead of opening it.

[blue]Your Thoughts? . . .[/blue]


See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
You might also want to consider error trapping in the Excel sheet.

The Data > Validation feature can prevent certain errors from being entered, like alpha characters in number fields.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks for the replies, y'all.

SkipVought, good idea and I have already doctored the Excel file with an assortment of things that will definitely help the situation -- as long as the user who will be sending us the info will start from the Excel template we provide them (I turned it into a .xltx file with various error signals and locked up a lot of it). The originator of this file is actually another office, so our control over what those folks will do is somewhat limited.

Lameid and TheAceMan1, I'll have to see if I can figure out how to do what y'all suggest. I tried putting all but the "error" form close into a public module and doing the rest of the stuff from there, but that didn't solve the problem. I'm not sure I currently know how to control the *entire* set of actions from a public module (I've spent a significant amount of time over the last 5-7 years hacking at VBA, but I'm not a programmer by degree or trade), but I might be able to figure it out with some extra time. So thanks for letting me know how y'all would do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top