E
Eric
I have a template that has 100 form fields, Scary. I am using the code
below to export the data in the form fields to an Access Database (Flat
Table) I then run Union Queries to extract from the Flat table into
normalized tables. this has been working great. But now I am finding out
that when the record (100 fields) are exported to only one table....... the
record size is to large for Access.
The code below exports all fields to one table. I need to break up this
export into say 5 different export functions. Each function will pull
specific form fields and export them to a specific table in access. then I
could run the 5 Export codes one after the other.
I'm not sure as to how to list the specific fields I want to export...... or
........ how to identify the specific tabel in Access I want to hit.
Any help on this would really be great, thanks in advance. Here is the code
that works fine, but I need to break it up into say 5 different macros.
Sub Export()
'
'
'
Dim vConnection As New ADODB.Connection
Dim vRecordSet As New ADODB.Recordset
Dim SH As Shell32.Shell
Dim Fldr As Shell32.Folder
Dim FldrPath As String
Dim RecordDoc As String
Dim dsource As String
Dim Source As Document
Dim i As Long, j As Long
Dim FileToKill As String
'Get the folder where the forms have been saved.
Set SH = New Shell32.Shell
Set Fldr = SH.BrowseForFolder(0, "Select the Directory (Folder) that
contains your Review Report", &H400)
If Not Fldr Is Nothing Then
FldrPath = Fldr.Items.Item.Path & "\"
End If
Set Fldr = Nothing
RecordDoc = Dir$(FldrPath & "*.doc")
With Dialogs(wdDialogFileOpen)
MsgBox "Locate the Review Tracker Database and select it"
If .Display <> -1 Then
dsource = ""
Else
dsource = WordBasic.FileNameInfo$(.Name, 1)
End If
End With
' Make sure the user selected an Access database
If Right(dsource, 3) <> "mdb" Then
MsgBox "You did not select a valid Access Database file type (.mdb) Review
Tracker. Locate the Review Tracker Database....and select it to proceed."
Exit Sub
Else
dsource = dsource & ";"
End If
vConnection.ConnectionString = "data source=" & dsource & _
"Provider=Microsoft.Jet.OLEDB.4.0;"
vConnection.Open
vRecordSet.Open "Review", vConnection, adOpenKeyset, adLockOptimistic
i = 0
While RecordDoc <> ""
vRecordSet.AddNew
Set Source = Documents.Open(FldrPath & RecordDoc)
With Source
For j = 1 To vRecordSet.Fields.Count
If .Bookmarks.Exists(vRecordSet.Fields(j - 1).Name) Then
If .FormFields(vRecordSet.Fields(j - 1).Name).Result <> ""
Then
vRecordSet(vRecordSet.Fields(j - 1).Name) = _
.FormFields(vRecordSet.Fields(j - 1).Name).Result
End If
End If
Next j
End With
vRecordSet.Update
i = i + 1
FileToKill = Source.FullName
Source.SaveAs FldrPath & "Processed\" & Source.Name
Source.Close wdDoNotSaveChanges
Kill FileToKill
RecordDoc = Dir
Wend
MsgBox i & " Records Added."
vRecordSet.Close
vConnection.Close
Set vRecordSet = Nothing
Set vConnection = Nothing
End Sub
below to export the data in the form fields to an Access Database (Flat
Table) I then run Union Queries to extract from the Flat table into
normalized tables. this has been working great. But now I am finding out
that when the record (100 fields) are exported to only one table....... the
record size is to large for Access.
The code below exports all fields to one table. I need to break up this
export into say 5 different export functions. Each function will pull
specific form fields and export them to a specific table in access. then I
could run the 5 Export codes one after the other.
I'm not sure as to how to list the specific fields I want to export...... or
........ how to identify the specific tabel in Access I want to hit.
Any help on this would really be great, thanks in advance. Here is the code
that works fine, but I need to break it up into say 5 different macros.
Sub Export()
'
'
'
Dim vConnection As New ADODB.Connection
Dim vRecordSet As New ADODB.Recordset
Dim SH As Shell32.Shell
Dim Fldr As Shell32.Folder
Dim FldrPath As String
Dim RecordDoc As String
Dim dsource As String
Dim Source As Document
Dim i As Long, j As Long
Dim FileToKill As String
'Get the folder where the forms have been saved.
Set SH = New Shell32.Shell
Set Fldr = SH.BrowseForFolder(0, "Select the Directory (Folder) that
contains your Review Report", &H400)
If Not Fldr Is Nothing Then
FldrPath = Fldr.Items.Item.Path & "\"
End If
Set Fldr = Nothing
RecordDoc = Dir$(FldrPath & "*.doc")
With Dialogs(wdDialogFileOpen)
MsgBox "Locate the Review Tracker Database and select it"
If .Display <> -1 Then
dsource = ""
Else
dsource = WordBasic.FileNameInfo$(.Name, 1)
End If
End With
' Make sure the user selected an Access database
If Right(dsource, 3) <> "mdb" Then
MsgBox "You did not select a valid Access Database file type (.mdb) Review
Tracker. Locate the Review Tracker Database....and select it to proceed."
Exit Sub
Else
dsource = dsource & ";"
End If
vConnection.ConnectionString = "data source=" & dsource & _
"Provider=Microsoft.Jet.OLEDB.4.0;"
vConnection.Open
vRecordSet.Open "Review", vConnection, adOpenKeyset, adLockOptimistic
i = 0
While RecordDoc <> ""
vRecordSet.AddNew
Set Source = Documents.Open(FldrPath & RecordDoc)
With Source
For j = 1 To vRecordSet.Fields.Count
If .Bookmarks.Exists(vRecordSet.Fields(j - 1).Name) Then
If .FormFields(vRecordSet.Fields(j - 1).Name).Result <> ""
Then
vRecordSet(vRecordSet.Fields(j - 1).Name) = _
.FormFields(vRecordSet.Fields(j - 1).Name).Result
End If
End If
Next j
End With
vRecordSet.Update
i = i + 1
FileToKill = Source.FullName
Source.SaveAs FldrPath & "Processed\" & Source.Name
Source.Close wdDoNotSaveChanges
Kill FileToKill
RecordDoc = Dir
Wend
MsgBox i & " Records Added."
vRecordSet.Close
vConnection.Close
Set vRecordSet = Nothing
Set vConnection = Nothing
End Sub