Good day..
I currently have a module that imports a MS word Document. I currently Run the import by opening the module and F5 which which then provides me with a popup asking my document name. I was wondering if it is possible to place this as a command on a form.
I did to copy/paste this code to the Click event of a Command Button but no luck, The code starts as follow.
Can someone please advise if i am missing something
Kind Regards
Susan
I currently have a module that imports a MS word Document. I currently Run the import by opening the module and F5 which which then provides me with a popup asking my document name. I was wondering if it is possible to place this as a command on a form.
I did to copy/paste this code to the Click event of a Command Button but no luck, The code starts as follow.
Can someone please advise if i am missing something
Kind Regards
Susan
Code:
Option Compare Database
Option Explicit
Function FixField(vIn, Vout) 'determine the value to use if field is empty
If IsNull(vIn) Or Trim(vIn) = "" Then FixField = Vout Else FixField = vIn
End Function
Sub GetWordData()
Dim appWord As Object
Dim doc As Object
Dim rst As New ADODB.Recordset
Dim rstSkills As New ADODB.Recordset
Dim rstLanguage As New ADODB.Recordset
Dim rstEducation As New ADODB.Recordset
Dim rstWork As New ADODB.Recordset
Dim rstRefs As New ADODB.Recordset
Dim sSQL As String
Dim n As Integer
Dim l As Long
Dim strDocName As String
Dim blnQuitWord As Boolean
On Error GoTo ErrorHandling
strDocName = gcDocPath & "\" & InputBox("Enter The Name Of The Form You Would Like To Import", "Import Personal Data From")
Set appWord = GetObject(, "Word.Application")
Set doc = appWord.Documents.Open(strDocName)
Dim ID As String
ID = FixField(doc.FormFields("ID").Result, 0)
If ID <= 0 Then
MsgBox "Unable to find user ID in document - cannot import record", vbExclamation
Set rst = Nothing
Set appWord = Nothing 'leave word doc open for user review
Exit Sub
End If
rst.Open "SELECT * FROM tblPersonnelInfo WHERE ID = " & ID, CurrentProject.Connection, adOpenDynamic, adLockOptimistic, adCmdText
If rst.EOF Then
MsgBox "Unable to find user ID in database - cannot import record", vbExclamation
Set rst = Nothing
Set appWord = Nothing 'leave word doc open for user review
Exit Sub
End If
'***************** START OF PERSONNEL INFO UPDATE *******************************
With rst
!Title = doc.FormFields("Title").Result
etc etc