Export to Word using Inputbox (1 Viewer)

JPR

Registered User.
Local time
Today, 01:37
Joined
Jan 23, 2009
Messages
192
Hello,

I am exporting data from a form to a Word template using bookmarks and would like to include an input box which users can use to add additional information which is not stored in the form.

I am getting an If without Else error and not sure if the code is correct. Appreciate your help. Below please find the code:

Code:
Private Sub Command111_Click()

On Error Resume Next
Dim objWord As Object
Dim strPath As String
Dim response As String
Dim MSG As String
Dim MyNote As String


strPath = DLookup("[TemplateLocation]", "TablePath", "[TemplateID]='" & Me.[txtpathLetter] & "'")

Set objWord = CreateObject("Word.Application")
objWord.Visible = False
objWord.Documents.Add strPath

' fields on my form that get exported to Word

objWord.ActiveDocument.Bookmarks("NAME").Select
objWord.Selection.Text = Me.CLFNAME & " " & Me.CLLNAME

' YES/NO Option asking user if certain data is available
' If Yes, type this data using an input box which needs to propagate to the bookmark FileNo
' If NO, then a msgbox will show up

MSG = MsgBox(MyNote, vbYesNo, "Do you have file number?")
If MSG = vbYes Then
Do
response = InputBox("FileNO", "Enter File number")
objWord.ActiveDocument.Bookmarks("FileNo").Select
objWord.Selection.Text = response
Else
response = MsgBox("please manually enter the file no.")
end if

objWord.Visible = True
 

JPR

Registered User.
Local time
Today, 01:37
Joined
Jan 23, 2009
Messages
192
Great. Working perfectly now. Thanks
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 03:37
Joined
Feb 28, 2001
Messages
27,179
Just to clarify: Your ACTUAL error was "improperly terminated DO" but Access detected it by the fact that the IF statement just before it did not have an End If in the same code block. I.e. the ELSE and END IF were inside the DO's code block but the IF was not.

That's because anything that has "split" syntax elements (IF/ELSE/END IF or DO/WHILE or FOR/END) defines a virtual "block" of code that is bracketed by the beginning and ending elements. Access doesn't like it if you overlap those elements in such a way that one part is inside a "block" but the other part is not. This kind of error will happen for ANY of those combinations if you do the "improper" syntax overlap.
 

Users who are viewing this thread

Top Bottom