Solved Extract Forms/Reports/Scripts/Modules/Queries from external database (1 Viewer)

Alt

Member
Local time
Today, 16:53
Joined
Sep 6, 2021
Messages
35
Hi guys,

I'm able to import tables from an external file (each table renamed) but having en error message (see mod_ExportDocs). Can you help me to figure out plz?

Merry Christmas to everyone!
 

Attachments

  • dbobjects.png
    dbobjects.png
    15.4 KB · Views: 63
  • DBObjects_ML.zip
    210 KB · Views: 101

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:53
Joined
Feb 19, 2002
Messages
43,427
On what line of code? Did you include the database you are linking to?
When you want us to debug something, you need to give us all the pieces and tell us where the error is happening.
 

Alt

Member
Local time
Today, 16:53
Joined
Sep 6, 2021
Messages
35
On what line of code? Did you include the database you are linking to?
When you want us to debug something, you need to give us all the pieces and tell us where the error is happening.
Everything is well attached... You have the error message when you press "Export Docs" button
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:53
Joined
Feb 19, 2002
Messages
43,427
1. This is the message I get. I'm assuming it thinks some db named TestDB.accdb should be in the folder but of course, it wasn't included in the download so it isn't there. Am I supposed to create an empty database with this name?
xxxExportError.JPG


2. I created the db but of course that wasn't the problem at all. It needs to be a db with objects in it.

3. VOILA! Turns out the problem is caused by sloppy coding. EVERY module should have as its first two lines:
Code:
Option Compare Database
Option Explicit
So, start by changing the Access option to require variable declaration. Then fix the compile errors to fix your problem.
 

Alt

Member
Local time
Today, 16:53
Joined
Sep 6, 2021
Messages
35
1. This is the message I get. I'm assuming it thinks some db named TestDB.accdb should be in the folder but of course, it wasn't included in the download so it isn't there. Am I supposed to create an empty database with this name?
View attachment 105432

2. I created the db but of course that wasn't the problem at all. It needs to be a db with objects in it.

3. VOILA! Turns out the problem is caused by sloppy coding. EVERY module should have as its first two lines:
Code:
Option Compare Database
Option Explicit
So, start by changing the Access option to require variable declaration. Then fix the compile errors to fix your problem.
you can read any external db but I've revised the zip files to include this testDB.accdb.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:53
Joined
Feb 19, 2002
Messages
43,427
That's fine but we don't know you your app works so you might have mentioned that. Did you fix the Option Explicit since that was what hid the problem from you?
 

Alt

Member
Local time
Today, 16:53
Joined
Sep 6, 2021
Messages
35
That's fine but we don't know you your app works so you might have mentioned that. Did you fix the Option Explicit since that was what hid the problem from you?
If you want to see my error message, press "Go" button (this will fill the form) then "Export Docs". You cna chech "mod_ExportDocs" (into VB editor)
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:53
Joined
Feb 19, 2002
Messages
43,427
Did you understand my instruction on HOW TO FIX THE ERROR? You have dim'd the database name as dbs but most of the references are to db. If you had Option Explicit turned on, you would see this because of the compile errors it causes!!
 

Alt

Member
Local time
Today, 16:53
Joined
Sep 6, 2021
Messages
35
Did you understand my instruction on HOW TO FIX THE ERROR? You have dim'd the database name as dbs but most of the references are to db. If you had Option Explicit turned on, you would see this because of the compile errors it causes!!
yes I put those two lines in every module and I no longer have an error message (Thanks... zip file is updated)
But I'm still unable to create txt files when I hit Export Docs" (mod_ExportDocs).
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:53
Joined
Feb 19, 2002
Messages
43,427
Did you fix the compile errors? You have a variable defined with one name but you are using a different name in the rest of the code. Therefore IT DOES NOT COMPILE. Code that does not compile rarely actually works:( FIX the compile errors to fix the problem.
 

ebs17

Well-known member
Local time
Today, 22:53
Joined
Feb 7, 2020
Messages
1,963
Application.SaveAsText acForm, doc.Name, sExtDbPath & Format(Date, "yyyymmdd") & doc.Name & ".txt"

SaveAsText creates text files. These are to be stored in a folder in the file system, not in an access file. Consequently, one would not use a file selection dialog here, but a directory selection dialog to generate valid paths for the export.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:53
Joined
May 7, 2009
Messages
19,246
here test this one:

the reason that your code does not work is that you are using Application.SaveAsText.
the "Application" there pertains to the Currentdb's Application and not the External db's Application.
remember the Forms (or objects) you are trying to Export is in another db not in the Currentdb.

you need to Open an Access.Application, and open the external db using the New access instance.
 

Attachments

  • DBObjects_ML.zip
    202.8 KB · Views: 74
  • Like
Reactions: Alt

Alt

Member
Local time
Today, 16:53
Joined
Sep 6, 2021
Messages
35
here test this one:

the reason that your code does not work is that you are using Application.SaveAsText.
the "Application" there pertains to the Currentdb's Application and not the External db's Application.
remember the Forms (or objects) you are trying to Export is in another db not in the Currentdb.

you need to Open an Access.Application, and open the external db using the New access instance.
working fine... Thanks a lot.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:53
Joined
Feb 19, 2002
Messages
43,427
If it is working, I guess you fixed the compile errors.
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:53
Joined
Sep 21, 2011
Messages
14,400
arnelgp provide a solution (no mention of compile errors...)
Really?
Here are two
Code:
Private Sub Commande19_Click()
    Call ImportAllFrms(txtFilename)
End Sub

Private Sub Commande20_Click()
    Call ImportAllQrys(txtFilename)
End Sub

Functions do not exist. However there only appears to be one button now to import everything?
Any that did exist, arnel would have likely corrected anyway.
 

Alt

Member
Local time
Today, 16:53
Joined
Sep 6, 2021
Messages
35
Really?
Here are two
Code:
Private Sub Commande19_Click()
    Call ImportAllFrms(txtFilename)
End Sub

Private Sub Commande20_Click()
    Call ImportAllQrys(txtFilename)
End Sub

Functions do not exist. However there only appears to be one button now to import everything?
Any that did exist, arnel would have likely corrected anyway.
some modules was removed because I don't have any issue with.
 

Users who are viewing this thread

Top Bottom