How to Increment Column For Each Record thru Module



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
.



Relevant Pages

  • RE: Find text in a word document
    ... Dim WordApp As Word.Application ... Dim WordWasNotRunning As Boolean ... Dim srchResults As String ... When trying to execute a "find" in the word document from an Excel ...
    (microsoft.public.excel.programming)
  • Re: Two problems sending an E-mail for Outlook 2007 and VB 2005
    ... I used the same open as it it was a Word document and did the content.text command to get it into the body of the message. ... I'd suspect that you aren't getting a valid Account object, I've used SendUsingAccount with valid Account objects with no problems, although reading that object property only works right in a Send event. ... Dim WordContent As String ... Dim SendPersonName As String ...
    (microsoft.public.outlook.program_vba)
  • Import Word form Into Access table with VBA Code
    ... Dim appWord As Word.Application ... Dim strDocName, strFile, strFolder As String ... Set appWord = GetObject ... MsgBox "You must select a valid Word document. ...
    (microsoft.public.access.modulesdaovba)
  • RE: How to Increment Column For Each Record thru Module
    ... Dim appWord As Word.Application ... Dim strDocName As String ... Set appWord = CreateObject ... Loop 'END OF LOOP ...
    (microsoft.public.access.modulesdaovba)
  • RE: How to Increment Column For Each Record thru Module
    ... I am importing Word Document Form into access table. ... Dim appWord As Word.Application ... Dim strDocName As String ... Set appWord = CreateObject ...
    (microsoft.public.access.modulesdaovba)