combo not allowing to copy value

pike

New member
Local time
Tomorrow, 08:42
Joined
Feb 14, 2016
Messages
9
[Solved] combo not allowing to copy value

Hi,
I am using the following code to generate a word document from a userform combo and textbox values and word Formfields

Code:
 Set Doc = appword.Documents.Open(Path, , True)
    With Doc
        .FormFields("txtstudent").Result = Me.Assigned_To.Column(1)
        .FormFields("txtid").Result = Me.[ID]
        .FormFields("txtopendate").Result = Me.Opened_Date
        .FormFields("txtopenedby").Result = Me.Opened_By.Column(1)
        .FormFields("txtassignedto").Result = Me.Assigned_To.Column(1)
        .FormFields("txtstudent2").Result = Me.Customer.Column(1)
        .FormFields("txtdescription").Result = Me.[Description]
        .FormFields("txtmisdemeanor").Result = Me.[Type of misdemeanor]
        .FormFields("txtlevel").Result = Me.[Level]
        .FormFields("txtActionTaken").Result = Me.[Action Taken]' this doesn't work
         .FormFields("txtassignedto2").Result = Me.Assigned_To.Column(1)
    End With
all works well transferring the records except Me.[Action Taken]
which even though the data is visible in the combo it will not transfer to the word doc. Other combos allow the transfer Me.[Type of misdemeanour] ect..but not Me.[Action Taken]

Me.Action_Taken.column(1) works if there is only on value

l tried loop all the values in the combo which were seleted but it just returned all the values.
The list is a typed array in Row Source

what could be the possible problem?
 
Last edited:
Solved the problem by adding a dummy set of values to the array changed the column count to two and bound column one

Code:
Sub fillwordform()
    Dim appword As Word.Application
    Dim Doc As Word.Document
    Dim Path As String
     On Error Resume Next
    Error.Clear
    Path = "C:\Users\user\Documents\New folder 3\Case.docx"
    'Path = "C:\Users\user\Documents\New folder 3\TimeOut sheet.dotm"
     Set appword = GetObject(, "word.application")
     Set Doc = appword.Documents.Open(Path, , True)
    With Doc
        .FormFields("txtstudent").Result = Me.Assigned_To.Column(1)
        .FormFields("txtid").Result = Me.[ID]
        .FormFields("txtopendate").Result = Me.Opened_Date
        .FormFields("txtopenedby").Result = Me.Opened_By.Column(1)
        .FormFields("txtassignedto").Result = Me.Assigned_To.Column(1)
        .FormFields("txtstudent2").Result = Me.Customer.Column(1)
        .FormFields("txtdescription").Result = Me.[Description]
        .FormFields("txtmisdemeanor").Result = Me.[Type of misdemeanor]
        .FormFields("txtlevel").Result = Me.[Level]
        .FormFields("txtActionTaken").Result = Me.[Action Taken]
        .FormFields("txtassignedto2").Result = Me.Assigned_To.Column(1)
    End With
     Doc.SaveAs "C:\Users\user\Documents\New folder 3\pTest.docx"
    Doc.Close
    
     If Me.Dirty Then
        Me.Dirty = False
    End If
    Attachments.SetFocus
    
    Call loadAttachFromFile("C:\Users\user\Documents\New folder 3\pTest.docx", Me.Recordset, "Attachments")
     VBA.Kill "C:\Users\user\Documents\New folder 3\pTest.docx"
     
    If Me.Attachments.AttachmentCount = 0 Then
        MsgBox "Missing Information Required", vbOKOnly, "Word Document Not Attached"
    End If
     Set Doc = Nothing
    Set appword = Nothing
 End Sub
 Public Sub loadAttachFromFile(strPath As String, rsAll As DAO.Recordset, attachmentFieldName As String)
    Dim rsAtt As DAO.Recordset
    Set rsAtt = rsAll.Fields(attachmentFieldName).Value
    rsAll.Edit
    rsAtt.AddNew
    rsAtt.Fields("FileData").LoadFromFile (strPath)
    rsAtt.Update
    rsAll.Update
 End Sub
 

Users who are viewing this thread

Back
Top Bottom