Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access 我正在考虑从子窗体向word传递访问数据_Ms Access_Vba - Fatal编程技术网

Ms access 我正在考虑从子窗体向word传递访问数据

Ms access 我正在考虑从子窗体向word传递访问数据,ms-access,vba,Ms Access,Vba,我试图将子表单中的数据复制到word中,如果数据超过1行(例如第一行=3只猫,第二行=1只狗(我![pets_信息]![PetType]),我只能将3只猫复制到word中,我将导入旧表单-文本表单字段 我需要做到的是:-3只猫,1只狗在一个文本字段中 我在互联网上能找到的似乎很少,总是从主表单中找到,而没有关于子表单/子表单的内容 我需要设置3个表,以便所有表都有自己的keyID 函数FillLetter() 将appword设置为Word.Application Dim doc作为Word.D

我试图将子表单中的数据复制到word中,如果数据超过1行(例如第一行=3只猫,第二行=1只狗(我![pets_信息]![PetType]),我只能将3只猫复制到word中,我将导入旧表单-文本表单字段

我需要做到的是:-3只猫,1只狗在一个文本字段中

我在互联网上能找到的似乎很少,总是从主表单中找到,而没有关于子表单/子表单的内容

我需要设置3个表,以便所有表都有自己的keyID

函数FillLetter()

将appword设置为Word.Application Dim doc作为Word.Document 将路径设置为字符串

On Error Resume Next
Err.Clear
''''''Chaange for which computer''''''''''''''
path = "F:\Access Stuff\Job for John - PSA\Homestay Provider Information.docx"
'path = "G:\Access Stuff\Job for John - PSA\Homestay Provider Information.docx"
Set appword = GetObject(, "word.application")
If Err.Number <> 0 Then
    Set appword = New Word.Application
    appword.Visible = True
End If
    Set doc = appword.Documents.Open(path, , True)
    With doc
        .FormFields("txtClientsFName").Result = (Me.Title) & " " & (Me!ClientFirstName) & " " & (Me!ClientFamilyName) '''works
        .FormFields("txtAddress").Result = (Me!Address) '''works
        .FormFields("txtSuburb").Result = (Me!Suburb) & ", WA " & (Me.PostCode) '''works


        .FormFields("txtContactType2").Result = (Me![Contact_Information]![ContactType]) & " " & (Me![Contact_Information]![ContactDetails])

        .FormFields("txtFamily").Result = (Me![Family_Information]![Relationship]) & " " & (Me![Family_Information]![Age])

        .FormFields("txtPolice").Result = Me!LegalCert '''works
        .FormFields("txtCosts").Result = Me!CPW '''works
        .FormFields("txtMeals").Result = Me.IEMeals '''works

        .FormFields("txtPets").Result = (Me![Pets_Infomation]![PetType])

        .FormFields("txtHobbies").Result = Me!HobbiesInterests '''works
        .FormFields("txtInstitute").Result = Me.Institution '''works
        .FormFields("txtTravel").Result = Me.ToUniCollege '''works
        .FormFields("txtOther").Result = Me!OtherInformation '''works
        .Visible = True
        .Activate
    End With

Set doc = Nothing
Set appword = Nothing
出错时继续下一步
呃,明白了
换哪台电脑
path=“F:\Access Stuff\Job for John-PSA\Homestay Provider Information.docx”
'path=“G:\Access Stuff\Job for John-PSA\Homestay Provider Information.docx”
设置appword=GetObject(,“word.application”)
如果错误号为0,则
设置appword=newword.Application
appword.Visible=True
如果结束
Set doc=appword.Documents.Open(路径,True)
和医生
.FormFields(“txtClientsFName”).Result=(Me.Title)和“&(Me!ClientFirstName)和“&(Me!ClientFamilyName)”有效
.FormFields(“txtAddress”).Result=(Me!Address)“有效”
.FormFields(“txtpuborary”).Result=(Me!郊区)和“、WA”和(Me.PostCode)”作品
.FormFields(“txtContactType2”).Result=(Me![联系人信息]![联系人类型]&“&(Me![联系人信息]![联系人详细信息])
.FormFields(“txtFamily”).Result=(我![家庭信息]![关系]&“&(我![家庭信息]![年龄])
.FormFields(“txtPolice”).Result=Me!勒格尔塞特的作品
.FormFields(“txtCosts”).Result=Me!共青团工程
.FormFields(“txtFines”).Result=Me.iefines“有效”
.FormFields(“txtPets”).Result=(Me![Pets\u information]![PetType])
.FormFields(“txt嗜好”).Result=Me!“兴趣爱好”的作品
.FormFields(“txtInstitute”).Result=Me.Institution“工作
.FormFields(“txtTravel”).Result=Me.tounicolege“有效
.FormFields(“txtOther”).Result=Me!“其他信息”起作用
.Visible=True
.激活
以
设置文档=无
设置appword=Nothing

结束函数

您可以使用RecordsetClone获取底层子表单数据

将此函数添加到表单中(确保常量与子表单/字段匹配):

Private Function GetPetTypes() As String

    Const SUBFORM_NAME  As String = "Pets_Infomation"
    Const PET_TYPEFIELD As String = "PetType"

    Dim strPetList  As String

    With Me(SUBFORM_NAME).Form.RecordsetClone

        If .RecordCount > 0 Then
            ' Start with first record
            .MoveFirst

            Do While Not .EOF
                If strPetList <> "" Then
                    strPetList = strPetList & ","
                End If
                strPetList = strPetList & .Fields(PET_TYPEFIELD)
                .MoveNext
            Loop

            ' Go Back to first record in case it needs to be reused
            .MoveFirst
        End If
    End With

    GetPetTypes = strPetList

End Function
   .FormFields("txtPets").Result = (Me![Pets_Infomation]![PetType])
使用此行

   .FormFields("txtPets").Result = GetPetTypes()

您可以使用RecordsetClone获取基础子表单数据

将此函数添加到表单中(确保常量与子表单/字段匹配):

Private Function GetPetTypes() As String

    Const SUBFORM_NAME  As String = "Pets_Infomation"
    Const PET_TYPEFIELD As String = "PetType"

    Dim strPetList  As String

    With Me(SUBFORM_NAME).Form.RecordsetClone

        If .RecordCount > 0 Then
            ' Start with first record
            .MoveFirst

            Do While Not .EOF
                If strPetList <> "" Then
                    strPetList = strPetList & ","
                End If
                strPetList = strPetList & .Fields(PET_TYPEFIELD)
                .MoveNext
            Loop

            ' Go Back to first record in case it needs to be reused
            .MoveFirst
        End If
    End With

    GetPetTypes = strPetList

End Function
   .FormFields("txtPets").Result = (Me![Pets_Infomation]![PetType])
使用此行

   .FormFields("txtPets").Result = GetPetTypes()