I'm using a code to open a Word document using Access and then filling form fields.
I'm having no problems with the code, but I want to change it so that the text box takes multiple IDs (an ID in each line) and perform the rest of the code on each code,
I've tried Split and other stuff I found by searching but I had no success.
I've tried to add to the code so that it saves the form automatically after filling the fields, would that work with multiple IDs?
Here's the code I'm using atm:
Dim appWord As Word.Application
Dim doc As Word.Document
On Error Resume Next
Err.Clear
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set appWord = New Word.Application
End If
Set doc = appWord.Documents.Open("C:\Users\" & Environ$("Username") & "\Desktop\Form.doc", , True)
With doc
.FormFields("Text4").Result = DLookup("[Name]", "[Que]", "[Qu]![ID] =" & [ID2])
appWord.Visible = True
.Activate
End With
Set doc = Nothing
Set appWord = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
End Sub
Edit: iIgot it to work using
Split(ID2.Value, ",")
However, I tried making it split values after each new line but I still couldn't figure it out.
I tried Enviroment.NewLine, vbCrLf, vbCr, vbNewLine and vbLf. None of them worked
Split(Enviroment.NewLine)but i get an error saying (Invalid Qualifier) - user3249749