• Xuất dữ liệu từ form access vào table trong word
  • Xuất dữ liệu từ form access vào table trong word

    doandinhtam > 12-11-21, 07:45 AM

    Xin chào các bạn. Mình có vấn đề này xin được giúp đỡ
    Mình có 1 form main-sub liên kết với nhau bằng MALOP
    Mình muốn tạo 1 button ở mainform để khi bấm vào đó thì toàn bộ thông tin như Hovaten, namsinh, gioitinh của toàn bộ học sinh trong lớp sẽ tự động xuất ra 1 table trong file word có sẵn. Có bao nhiêu em thì tự tạo bấy nhiêu hàng table để tự thêm thông tin vào.
    Mong mọi ngưởi giúp đỡ ạ
  • RE: Xuất dữ liệu từ form access vào table trong word

    ongke0711 > 12-11-21, 08:23 AM

  • RE: Xuất dữ liệu từ form access vào table trong word

    doandinhtam > 16-11-21, 04:25 PM

    nói thật với bác là mấy nay em nghiên cứu mấy bài viết trên nhưng mà không hiểu gì...mong bác giúp đỡ
  • RE: Xuất dữ liệu từ form access vào table trong word

    ongke0711 > 16-11-21, 05:55 PM

    Bạn nên có file dữ liệu mẫu, file word để xem mặt mũi nó ra như thế nào chứ đâu thể code chạy từ a-z được.
  • RE: Xuất dữ liệu từ form access vào table trong word

    doandinhtam > 25-11-21, 10:47 AM

    https://drive.google.com/drive/folders/1...sp=sharing
     mình không biết đính kèm file nên gửi tạm folder google drive ạ. Trong đó có file word mẫu, mình muốn xuất danh sách từ access sang theo như file mẫu. mong bạn giúp đỡ
  • RE: Xuất dữ liệu từ form access vào table trong word

    ongke0711 > 25-11-21, 12:37 PM

    (25-11-21, 10:47 AM)doandinhtam Đã viết: https://drive.google.com/drive/folders/1...sp=sharing
     mình không biết đính kèm file nên gửi tạm folder google drive ạ. Trong đó có file word mẫu, mình muốn xuất danh sách từ access sang theo như file mẫu. mong bạn giúp đỡ

    Bạn xem file đính kèm.
    Link: https://www.mediafire.com/file/i8shd6yua...le.7z/file

    Code:

    Mã PHP:
    Public Function XuatDSHSWord()
        Dim db As DAO.Databasers As DAO.Recordset
        Dim oApp 
    As ObjectDoc As ObjectoWordTbl As Object
        Dim strSQL 
    As StringstrDocName As String
        Dim tblNoInDoc 
    As IntegeriCols As IntegeriRecCount As IntegeriFldCount As IntegerAs Integer
        
        On Error 
    GoTo EH
        
        Set oApp 
    CreateObject("Word.Application")
        'oApp.Visible = True
        
        On Error Resume Next
        
        strDocName = """" & CurrentProject.Path & "\DanhSachHocSinhLop.dotx" & """"
        Set Doc = oApp.Documents.Add(strDocName)
        
        
        Doc.FormFields("fldMaLop").Result = Me.txtMALOP
        Doc.FormFields("fldNamHoc").Result = Me.txtNAMHOC
        Doc.FormFields("fldChuNhiem").Result = Me.txtCHUNHIEM
        
        
        '
    Mo table can export qua file Doc'
        Set db = CurrentDb
        Set rs = Me.sfmHocSinh.Form.RecordsetClone
        With rs
            If .RecordCount <> 0 Then
                .MoveLast  '
    De lay chính xác sô dòng
                iRecCount 
    = .RecordCount  'Sô dòng
                .MoveFirst
                iFldCount = .Fields.Count - 1    '
    So Field trong table cân xuat
                
                tblNoInDoc 
    1  'So thu tu cua table trong file Doc'
                Set oWordTbl Doc.Tables(tblNoInDoc)
                'Them cot'
                With Doc.Tables(tblNoInDoc)
                    .Select
                    
    Do Until .Columns.Count iFldCount 1
                        
    .Columns.Add
                        
    .Columns.AutoFit
                    Loop
                End With
                
                
    'Dat ten cho dòng tiêu dê
                oWordTbl.Cell(1, 1) = "Stt"
                oWordTbl.Cell(1, 2) = "H" & ChrW(7885) & " T" & ChrW(234) & "n"
                oWordTbl.Cell(1, 3) = "N" & ChrW(259) & "m Sinh"
                oWordTbl.Cell(1, 4) = "Gi" & ChrW(7899) & "i T" & ChrW(237) & "nh"
                
                '
    Build our data rows'
                For i = 1 To iRecCount
                    Doc.Tables(tblNoInDoc).Rows.SetLeftIndent LeftIndent:=10, RulerStyle:=2
                    Doc.Tables(tblNoInDoc).Rows.Add
                    oWordTbl.Cell(i + 1, 1) = Nz(rs.Fields("ID").Value, "")
                    oWordTbl.Cell(i + 1, 1).Range.ParagraphFormat.Alignment = 1    '
    0 la can trai
                    oWordTbl
    .Cell(11).Range.Cells.VerticalAlignment 1
                    
                    oWordTbl
    .Cell(12) = Nz(rs.Fields("HoVaTen").Value"")
                    oWordTbl.Cell(12).Range.ParagraphFormat.Alignment 0
                    oWordTbl
    .Cell(12).Range.Cells.VerticalAlignment 1
                    
                    oWordTbl
    .Cell(13) = Nz(rs.Fields("NamSinh").Value"")
                    oWordTbl.Cell(13).Range.ParagraphFormat.Alignment 1
                    oWordTbl
    .Cell(13).Range.Cells.VerticalAlignment 1
                    
                    oWordTbl
    .Cell(14) = Nz(rs.Fields("GioiTinh").Value"")
                    oWordTbl.Cell(14).Range.ParagraphFormat.Alignment 1
                    oWordTbl
    .Cell(14).Range.Cells.VerticalAlignment 1
            
                    
    .MoveNext
                Next i
                
                
    'Dinh dang dòng tieu de
                With Doc.Tables(tblNoInDoc).Rows(1).Range
                    .Font.Bold = True
                    .ParagraphFormat.Alignment = 1
                    .Cells.VerticalAlignment = 1
                    .Shading.BackgroundPatternColor = RGB(225, 225, 225)    '
    16
                End With
                Doc
    .Tables(tblNoInDoc).Rows(1).Height 22
                
                
    'Thiet lap do rong tung côt
                Doc.Tables(tblNoInDoc).Columns(1).Width = 0.7 * 72
                Doc.Tables(tblNoInDoc).Columns(2).Width = 3 * 72
                Doc.Tables(tblNoInDoc).Columns(3).Width = 1.5 * 72
                Doc.Tables(tblNoInDoc).Columns(4).Width = 1.5 * 72
            End If
        End With
        
        rs.Close
        Set rs = Nothing
        Set oWordTbl = Nothing
        oApp.Visible = True
        Set oApp = Nothing
        
        MsgBox "Xuat Word hoan tat."
        
    EH_Exit:
        Exit Function
        
    EH:
        MsgBox Err.Description
        Resume EH_Exit
        
    End Function 
  • RE: Xuất dữ liệu từ form access vào table trong word

    doandinhtam > 26-11-21, 11:43 AM

    cám ơn bác nhiều lắm ạ
  • RE: Xuất dữ liệu từ form access vào table trong word

    doandinhtam > 26-11-21, 04:51 PM

    BÁC CHO EM HỎI ĐẶT TÊN TABLE TRONG WORD NHƯ NÀO Ạ? E THẤY CODE BÁC ĐỂ TABLE NAME LÀ tblNoInDocÀ 
  • RE: Xuất dữ liệu từ form access vào table trong word

    ongke0711 > 26-11-21, 05:18 PM

    (26-11-21, 04:51 PM)doandinhtam Đã viết: BÁC CHO EM HỎI ĐẶT TÊN TABLE TRONG WORD NHƯ NÀO Ạ? E THẤY CODE BÁC ĐỂ TABLE NAME LÀ tblNoInDocÀ 

    - tblnoInDoc là tên biến tôi đặt trong code VBA thôi, muốn đặt tên gì cũng được.
    - Trong Word không đặt tên Table mà chỉ lấy số theo thứ tự mà nó xuất hiện thôi. Trong file hiện tại chỉ có 1 table nên ID của nó sẽ là 1. Nếu có 2, 3 table thì cứ theo tuần tự nó sắp xếp trong Word mà xác định ID của nó.