MS Access VBA to run all saved imports together - ms-access

I am looking for a VBA code to run multiple saved imports in MS Access 2010. I used DoCmd.RunSavedImportExport "*" but gave an error.
I know I am doing something wrong here. Please understand I am a newbie to VBA. I have almost 8 saved imports in .csv formats in a specific location. All I want is to automate it through VBA.

i guess you have taken all other necessary steps already.
loop through the saved import/export and execute them one by one.
something like:
pseudo would be:
loop through the import/export and execute it manually.
in code would be:
Dim i As Integer
For i = 0 To CurrentProject.ImportExportSpecifications.count - 1
Debug.Print CurrentProject.ImportExportSpecifications(i).name
DoCmd.RunSavedImportExport CurrentProject.ImportExportSpecifications(i).name
Next i
EDIT
Your ImportExportSpecifications details are saved as XML format and you can access that information via
CurrentProject.ImportExportSpecifications(i).XML
within the XML you will find the path = "your file.xlsx". Do a string job to extract the path and validate the file ending and implement your code.

Related

How to call an Excel report from an other Excel report?

I have 12 Excel reports in my Application Lifecycle Management.
Each of them execute a Query and some VBA code when I click on generate.
I was wondering if it is possible to create a single Excel report that can call each of the previously mentioned reports so that I don’t have to manually generate each of them.
Is there a way?
Otherwise I think I’ll have to regroup and recode them in one big Excel report, which would not be practical for future modifications.
You can call macro from "starting file".
You need open file, start makro like bellow, close file and do the same with another
Application.Run "filename.xlsm!macroname"
EDIT:
sub test()
Workbooks.Open filepath & "\filename.xlsm"
Application.Run "filename.xlsm!macroname"
Windows(ActiveWorkbook.Name).Close
end sub

USING SSIS to check a file for words in the name

I'm trying to use SSIS to check if a file contains the words _nodata
If it does, I want to end the package execution. I have used script to check if there are files in a folder, but I can't figure out how to see if the file contains certain words. Thanks.
In your VB Script task, you can use the FileSystemObject to access the name of the file. I assume you are already using the FileSystemObject because you say you are checking to see if the file exists.
Read up on the FileSystemObject in MSDN to see all the properties it exposes, and learn how to access the file name and see if it contains "_nodata".

Creating a Document Database using Microsoft Access

I am attempting to create a table within a database which store all of the documents related to the database "in it". What I really want to do is have a file uploaded and have vba code which copies the file to a network location, renames the file by concatenating two fields from the document table form (eliminating the issue of duplicate file names in the external location), and then stores the file name and file path in a file path field in the table. I am very new to access and vba so I am having difficulty getting everything to work. The code I currently have is below:
Option Compare Database
Private Sub Command15_Click()
Dim f As Object
Set f = Application.FileDialog(3)
f.AllowMultiSelect = False
If f.Show Then
For i = 1 To f.SelectedItems.Count
sFile = Filename(f.SelectedItems(i), sPath)
MsgBox sPath & "---" & sFile
Next
End If
End Sub
Public Function Filename(ByVal strPath As String, sPath) As String
sPath = Left(strPath, InStrRev(strPath, "\"))
Filename = Mid(strPath, InStrRev(strPath, "\") + 1)
End Function
I can not seem to get a handle on how to move, rename by concatenating the two fields from the form, or store the path in the path field of the table. I have been to the following locations to obtain what information I could
ms access browse for file and get file name and path
VBA to copy a file from one directory to another
I am currently using Microsoft Access 2010, and I do not wish to use the file attachment field type because of database size constraints. Currently I press a button and a file explorer appears to navigate to the file being uploaded, and the path and file name are entered into strings. After this point I am lost. If any other information is needed please let me know. Thanks in advance for the assistance.
I believe your approach to managing the documents is right. In most cases, it doesn't make much sense to store documents in the database itself when the filesystem is a more suited to this job.
What you are doing is fairly straightforward but the main complexity will come from the correct management of the various paths and filenames and extracting the right information from them.
It can become tricky if you're not using some helper functions to to dissect and recompose the various bits of the paths.
I have created a sample database that has a few functions. Might not be exactly in line with what you need but you can easily play around with it to suit your particular case.
The sample database includes a Tools VBA module that has a few useful functions to split a Path into its constituents.
Basically, the database has 2 forms.
The main form allows you to set the network path where the files are to be saved.
You can then select a pre-defined Account number (listed in the Account table) associated with a document, then click the upload button.
This creates a new record in the Document table and opens a form where you can edit the document title and click a button to upload a file to the server.
The file selected by the user is copied to the server after its path has been transformed.
I took the assumption that the file would keep its original extension, the filename would be renamed to the ID of the Document record where the file information is saved (like 5845.pdf) and that the folder where the file is saved on the server would be the account number, so that a source file selected by the user
C:\Users\user\Desktop\SuperSecretFile.pdf
would be saved as, for instance:
\\docserver\files\123-55547\5845.pdf
The Main form also allows you to update an existing record, open the file from the server, open the server's folder where the file is located or even copy the server file back to the user's computer with the original name of the file.
I'll let you play around with it. Let me know if you have any issues.

SSIS Excel connection error "External table is not in the expected format."

Problem
-I have an excel spreadsheet generated a lotus app. It smells and looks like excel but Excel Source data flow source can not recognise it. When trying to select a table(tab) i get the following error message "External table is not in the expected format.”
-Opening the excel spreadsheet and save it again helps(File also reduces in size). But as dev we ara allegic to manual processes.
-I have tried to change the connection string using a variable
from
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DataImport\Lotus.xls;Extended Properties="Excel 8.0;HDR=YES";
To
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\DataImport\Lotus.xls;Extended Properties="EXCEL 12.0;HDR=YES";
If i can avoid the script task that would be great
I have had to open and close the excel file manually saving. Those bugs that can't be fixed
I had the same error, your post led me to open the excel file but my excel file was corrupt. I'm posting in case this helps someone else.

Storing PDFs in MS Access Database using Forms

I need to store PDF files in an Access database on a shared drive using a form. I figured out how to do this in tables (using the OLE Object field, then just drag-and-drop) but I would like to do this on a Form that has a Save button. Clicking the save button would store the file (not just a link) in the database. Any ideas on how to do this?
EDIT:
I am using Access 2003, and the DB will be stored on a share drive, so I'm not sure linking to the files will solve the problem.
We have several databases that contain 10's of thousands of documents (pdf, doc, jpg, ...), no problem at all. In Access, we use the following code to upload a binary object to a binary field:
Function LoadFileFromDisk(Bestand, Optional FileName As String = "")
Dim imgByte() As Byte
If FileName = "" Then FileName = strFileName
Open FileName For Binary Lock Read As #1
ReDim imgByte(1 To LOF(1))
Get #1, , imgByte
Close #1
If Not IsEmpty(imgByte) Then Bestand.Value = imgByte
End Function
In this case, Bestand is the field that contains the binary data.
We use MS SQL Server as a backend, but the same should work on an Access backend.
If you used the same concept but upsized to SQL Server- storing PDFs inside of an Image datatype (or varbinary(max)) then you could SEARCH INSIDE THE PDFs using Full Text Search.
I show that Microsoft says you can do this for any file type where you can register an IFILTER product.. and I just was at the Adobe website the other day and say that their Acrobat IFILTER is indeed FREE.
Maybe this will help: ACC2000: Reading, Storing, and Writing Binary Large Objects (BLOBs).
What they do: Read a file in chunks and add it to a blob using a VBA function.
A field of OLE Object, by default would use a Bound Object Frame on the form. Right click on it and you can Insert an object. It comes complete with browsing for the file. Double-click on the field and the actual document will open.
I recommend going with David's advice and link. Unless you have a need to transfer a single file and want all the PDF's included. Size and performance will be an issue.
If security is an issue and the Access file is the only control you have (You are unable to set security on the folder containing all the linked files.), then you would have to embed.