How to Increment Column For Each Record thru Module
- From: Reddy <Reddy@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 18 Jan 2007 07:20:04 -0800
Hello VB Gurus!
My below module works great but I have text column "TaskNo" which needs to
be increment for very word document form that I import. Please help me out.
'Code.............
Sub fImportTaskForm()
Dim appWord As Word.Application
Dim doc As Word.Document
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strDocName As String
Dim blnQuitWord As Boolean
Dim strfile As String
Dim strPath As String
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
On Error GoTo ErrorHandling
'File path '
strPath = "C:\MyWorks\"
'Change the default directory to the file path
ChDir strPath
'Find the firsttext file
strfile = Dir("*.doc")
'Loop through the string & import the files
Do While Len(strfile) > 0
Set appWord = CreateObject("Word.Application")
Set doc = appWord.Documents.Open(strPath & "\" & strfile)
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\database\" &
"Healthcare Contracts.mdb;"
rst.Open "Task", cnn, adOpenKeyset, adLockOptimistic
strMyVar = Replace(strfile, ".doc", "_")
With rst
.AddNew
![Account No] = 5075
![Alternate Task No] = doc.FormFields("fldTaskNum").Result
![Task Name] = doc.FormFields("fldApplication").Result & " " &
doc.FormFields("fldCategory").Result & " " &
doc.FormFields("fldSubcategory").Result
![Task Description] = doc.FormFields("fldTaskDesc").Result
![Point of Contact] = doc.FormFields("fldGContact").Result
![Estimated Hours] = doc.FormFields("fldTotalEstHrs").Result
![BillDate] = doc.FormFields("fldDateApproved").Result
.Update
.Close
End With
doc.Close
If blnQuitWord Then appWord.Quit
cnn.Close
Cleanup:
Set rst = Nothing
Set cnn = Nothing
Set doc = Nothing
Set appWord = Nothing
'Call Dir to get the next file
strfile = Dir
Loop 'END OF LOOP
MsgBox "USDA TASK Form Imported!"
Exit Sub
ErrorHandling:
Select Case Err
Case -2147022986, 429
Set appWord = CreateObject("Word.Application")
blnQuitWord = True
Resume Next
Case 5121, 5174
MsgBox "You must select a valid Word document. " _
& "No data imported.", vbOKOnly, _
"Document Not Found"
Case 5941
MsgBox "The document you selected does not " _
& "contain the required form fields. " _
& "No data imported.", vbOKOnly, _
"Fields Not Found"
Case Else
MsgBox Err & ": " & Err.Description
End Select
GoTo Cleanup
End Sub
.
- Follow-Ups:
- Prev by Date: Re: VB Error
- Next by Date: Re: Self closing DB
- Previous by thread: Re: VB Error
- Next by thread: RE: How to Increment Column For Each Record thru Module
- Index(es):
Relevant Pages
|