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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import text files to code modules 3

Status
Not open for further replies.

newmanje

IS-IT--Management
Jan 5, 2004
13
Using Access2k I am currently trying to recover my database from the 'Network Connection Lost' problem caused by importing objects from another database.

I have used DeanWilliams' code to export all objects to text files and set the HasModule property to false. I have now imported these into a fresh database.

Does anyone know of a way in which you can loop through the text files and import the code rather than doing it manually (nearly 300 objects)?

Any pointers would be appreciated.

Many thanks,

Jim
 
Sorry, I don't know of that, and you'd probably have to manually "refresh" the event per each control.

But - If you still have the original db, with the errors, you could try the /decompile option. This has in the past years resolved all my code corruption (even though it is marketed as something else;-)). A description of the method is found here:

Decompile or how to reduce Microsoft Access MDB/MDE size and decrease start-up times

MakeItSo's faq faq705-4683, also contains some info.

Roy-Vidar
 
Thanks Roy.

I'd already tried a decompile (as to date that has got us through previous problems). This time round it just didn't want to work so I went hunting for alternatives.

I'm sure there's a cleverer way to import the text files than manually copying and pasting. I know someone's brain is more switched on than mine I'm just hoping they'll see my message.
 
Hi,

If that doesn't work, you could probably use a procedure that does the opposite of each step in the other piece of code you used.

Let me know, if Roy's suggestion doesn't help. Then I will try and write some code to do what you want.

Dean :)
 
Hi Dean,

I'd already decompiled and that didn't work. That's why I'd found your code for exporting it and saving a whole load of time in the process - a lifesaver.

I've reversed the code to set the HasModule to true for the forms and reports it's just importing it from the text files that I can't figure out.

Thanks,

Jim
 
You might try using the AddFromFile method of the Module object. This will allow you to add code from a file into a standard Code Module, or a Class object, but I don't think it can be used for a Form object.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
You can also import from a text file into a form module from within the IDE using the "Insert->File" menu option. This is slightly better than copy/paste, but as RoyVidar said earlier, you still may have to manually re-attach the event handlers to the proper control.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I know it's probably to late for this now, but a while ago, there was a thread on something else, but there was this method of saving and retrieving info using the .SaveAsText and .LoadFromText (hidden) methods of the application object.

Here's the thread thread705-751080, I just did a very quick test on one of my db's, and it did work! Note however bboffin's reservations at the end of the thread.

Question is whether it's applicable in this case, where this method isn't used to save the info, but if it's possible to try to save the the objects this way now...

Here's a quick and dirty LoadAllFromText function. If you've saved with bboffin's code, then just create a new db, import/link all the tables, paste this function into a new module and run it using the same path... it actually recreates all objects! You should only have to set the references, compile, save and...

- note haven't tested this thouroughly, but all form/report events, and other code worked on rather complex db;-) Nice if it would decrease the amount of work for you, and would be interesting to hear how it worked on a corrupt db

[tt]Public Function LoadAllFromText(sPath)
Dim dbs As Object
Dim fso As Object
Dim fld As Object
Dim fls As Object
Dim fl As Object

Set dbs = CurrentDb
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(sPath)
Set fls = fld.Files
For Each fl In fls
Select Case Right$(fl.Name, 4)
Case ".xcf"
Application.LoadFromText acForm, _
Left$(fl.Name, Len(fl.Name) - 4), sPath & "\" & fl.Name
Case ".xcr"
Application.LoadFromText acReport, _
Left$(fl.Name, Len(fl.Name) - 4), sPath & "\" & fl.Name
Case ".xcm"
Application.LoadFromText acModule, _
Left$(fl.Name, Len(fl.Name) - 4), sPath & "\" & fl.Name
Case ".xcs"
Application.LoadFromText acMacro, _
Left$(fl.Name, Len(fl.Name) - 4), sPath & "\" & fl.Name
Case ".xcq"
Application.LoadFromText acQuery, _
Left$(fl.Name, Len(fl.Name) - 4), sPath & "\" & fl.Name
End Select
Next fl
Set dbs = Nothing
Set fso = Nothing
Set fld = Nothing
Set fls = Nothing
Debug.Print "Finished..."
End Function[/tt]


Roy-Vidar
 
Starworthy post RoyVidar.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Premature return.
I was not aware of those methods. Definately adding them into the toolbox.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thank you very much, CajunCenturion!

bboffin was the one bringing i to our attention, though, I've just "reversed" the function, but it's definitely going into my library too, after some more testing. Interesting when newmanje reports back with results on how (if) it works on a corrupt db.

Roy-Vidar
 
Hi Roy,

Thanks for the help. It wouldn't work in the corrupted database as it now refuses to allow any code to run (gives the 'Network connection error' every time. I'm about to try and see if I can find a way around this as the code both bboffin and you have seems like it's perfect for the job.

Thanks once again.
 
Free at last.

Roy and bboffin's code worked for everything but the forms - these still turned out to be corrupt. I subsequently used their code for all objects except forms, copied the code for the forms using DeanWilliams' code and manually pasted it back in (as suggested in Microsoft's oh-so-helpful support article).

The database is running fine. Thanks to everyone - you've saved me a lot of frustration.
 
I've been looking for DeanWilliams' Code, but can't seem to find it.... can anyone give me a url for it so I can look at it?
 
I think DeanWilliams have posted some of it previously. Try searching (one hint is using the member profile, and check thru DeanWilliams threads in the Access fora). I think also some code for this purpose by DeanWilliams, occurs in MakeItSo's faq faq705-4683. The code utilizes CurrentProject, which means versions 2000+

Roy-Vidar
 
Ok.. cool... Now... has anyone thought about creating an add-in or something that would save a form (or all of them) to a text file. I'm talking about the properties, the controls and all their properties, and the code.

If anyone has any ideas... I'm thinking maybe to save the form to look like a vb form (vb6 is what I use)... then it could also have an import feature that would read the file and recreate the form in another database.

I'm thinking about this because I have some forms that I want to keep, but I don't need them in the database. I'll probably just create an "Archive" database that would house these forms, but I would like to look at 'exporting' the forms to a text file... maybe even having it so that you can import them into a vb project, and have them look like they did in Access.....

Any help, hints, or pointers to where they are already created (don't want to recreate the wheel if I don't have to) are appreciated!

PS. I had some trouble posting this at first, so I just copied the text into a text file, and saved it, then went looking for the form to vb export help... and found a locked MDE add-in for MSAccess97... Can't find anything for 2000 or greater....

GComyn
 
If you are looking for some responses to my last question (I started a new thread), the thread is thread705-989746.

Gcomyn
 
Since the hidden methods .SaveAsText and .LoadFromText of the application object is mentioned in my second reply here, I'm not sure what I can learn by the referenced thread. Isn't it just the same?

Roy-Vidar
 
You're right... I guess I got distracted when I was reading this thread before, because I totally missed your post about that.... *sigh*...

Now... do you know where/how I can get the same functionality for tables? The format part, anyway... the data is easy...

GComyn
 
These methods won't work for tables. Depending on how thorough you wish to be, you'll need to somehow get to the properties of the table, browse their properties, names, types, description, required, autonumber... not to forget relationship... i e - I guess you'll need to take off the jacket and prepare for some coding;-)

I'm reasonable sure there are lot of stuff on that available thru search here, then also one member jrbarnett, has a documenter available thru their website (see the link section of this forum), that's quite good, and I think the source code is availble.

Here are some recent threads on some properties that may be of interest

thread181-983963, thread705-952556, thread181-986219, thread181-987928

My somewhat lazy approach, is that since I usually have the tables in the backend, it's only a matter of relinking them;-)

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top