By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,401 Members | 928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,401 IT Pros & Developers. It's quick & easy.

Need YOUR PROFESSIONAL HELP to Import Word Document in MS Access Tables

P: 6
Hello,

My problem is that I receive different Word Documents as attachments

and I need to get its data into the corresponding tables in access.


I have used Text Form Fields in Word Document and could save it in text format

and imported it in ms access, but this way takes long time.

So, I need your help to have a command button that when clicked I get a

browse window that enables me to choose the Word Documents (.doc Only) I want to import.

And as I have different Word Documents, I think I will need different command

buttons for each Word Document as each would be knowing which table to

import to.

Also is there anyway to minimize the possibility of importing a Document to the wrong table?

Is it possible to make the access import all documents saved in a specific folder to a specific table? I know this is fiction

Thank YOU and I really Trust Your Abilities in Solving my problem.

And I Really Appreciate your HELP
Oct 1 '08 #1
Share this Question
Share on Google+
4 Replies


ADezii
Expert 5K+
P: 8,669
The following Code Template, using only a single Command Button, will:
  1. Open a File Dialog Box which will only allow you to select either a single, or multiple, Word Documents.
  2. Process each File(s) selected, and then cross reference it/them against hard coded File Names.
  3. Take appropriate action (Append to proper Table) depending on the File(s) selected.
  4. If a File(s) is/are not on the List, display an Error Message to the User that it/they cannot be Imported.
  5. I intentionally omitted Comments in order to reduce the length of the code, but should you have any questions, please feel free to ask
Expand|Select|Wrap|Line Numbers
  1. 'Must set a Reference to the Microsoft Office XX.X Object Library
  2. Dim fdg As FileDialog
  3. Dim vrtSelectedItem As Variant
  4. Dim strSelectedFile As String
  5.  
  6. Set fdg = Application.FileDialog(msoFileDialogFilePicker)
  7.  
  8. With fdg
  9.   .AllowMultiSelect = True         'allow multiple Files to be selected
  10.   .Filters.Clear
  11.   .Filters.Add "Word Documents", "*.doc"
  12.   .FilterIndex = 1
  13.   .InitialView = msoFileDialogViewDetails
  14.     If .Show = -1 Then
  15.       For Each vrtSelectedItem In .SelectedItems
  16.         'Retrieve 'FileName only'
  17.         strSelectedFile = Right$(vrtSelectedItem, Len(vrtSelectedItem) - InStrRev(vrtSelectedItem, "\"))
  18.           Select Case strSelectedFile
  19.             Case "Some File 1.doc"
  20.               'code specific to Some File 1.doc
  21.             Case "Some File 2.doc"
  22.               'code specific to Some File 2.doc
  23.             Case "Some File 3.doc"
  24.               'code specific to Some File 3.doc
  25.             Case "Some File 4.doc"
  26.               'code specific to Some File 4.doc
  27.             Case "Some File 5.doc"
  28.               'code specific to Some File 5.doc
  29.             Case "Some File 6.doc"
  30.               'code specific to Some File 6.doc
  31.             Case "Some File 7.doc"
  32.               'code specific to Some File 7.doc
  33.             Case "Some File 8.doc"
  34.               'code specific to Some File 8.doc
  35.             Case "Some File 9.doc"
  36.               'code specific to Some File 9.doc
  37.             Case "Some File 10.doc"
  38.               'code specific to Some File 10.doc
  39.             Case Else
  40.               MsgBox "[" & strSelectedFile & "] cannot be Imported!", vbExclamation, "Import Failed"
  41.           End Select
  42.       Next vrtSelectedItem
  43.     Else 'The user pressed Cancel.
  44.     End If
  45. End With
P.S. - Be sure to set a Reference to the Microsoft Office XX.X Object Library
Oct 1 '08 #2

P: 6
Thank You ADezii,

but I have only one more thing to add which is that the file names I receive are

not static as some dates and numbers would be added to the original file name.

and I think this what causes the problem with the code

Thanks ALOT
Oct 1 '08 #3

ADezii
Expert 5K+
P: 8,669
Thank You ADezii,

but I have only one more thing to add which is that the file names I receive are

not static as some dates and numbers would be added to the original file name.

and I think this what causes the problem with the code

Thanks ALOT
The code can be modified to accommodate 'Unique', 'Original' File Names. A simple example of what I am referring to would be if a Base File Name was Financial Report. The code can be modified to accept: Third Quarter Financial Report, Financial Report for the Fiscal Year 2008, Projected Financial Report for 2010, etc. Let me know if you are interested, and if you have Unique, Base/Original File Names.
Oct 1 '08 #4

P: 6
Hello ADezii,

infact the name of the document should be written exactly in the code so that I

would be able to import it and if there is any change in the name of the file the

code gives an error that it can't import it it..

anyway even I made the table name with same name of the file and the import

apparently finishes successfully,then I don't find any data entered in the table.
Oct 1 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.