vba - Populating Word Tables from Access -


i trying create tables in ms word , fill them data ms access. of code have written below in basmain , basutilities. having trouble private sub fillcells in basmain. used sub fill tables text fields, table needs allow other formats. data listed in basutilites text except tblemployees.[notes] , tblemployees.[photo]. notes memo , on limit of characters text , photo bmp picture. also, tables should not have form fields. appreciated. thank you!!

here link source files: https://jumpshare.com/b/sy6mxurdtdpssdcqkluj

basmain

option explicit public const cstrpath string = "\source\243src_final.accdb" public connemp adodb.connection public rstemps adodb.recordset sub listemps()   dim strask string   strask = inputbox("which country?", "county request")   if strask = "uk"     call basutilities.connect("uk")   elseif strask = "usa"     call basutilities.connect("usa")   else     msgbox "this name not recognized!"   end if end sub public sub createtables()   dim sngrecords single, intfields integer, inti integer   sngrecords = rstemps.recordcount   intfields = rstemps.fields.count   rstemps.movefirst   inti = 1 sngrecords     dim intf integer     selection.typeparagraph     activedocument.tables.add range:=selection.range, numrows:=intfields, numcolumns:= _     2, defaulttablebehavior:=wdword9tablebehavior, autofitbehavior:=wdautofitcontent     selection.tables(1)       .columns.preferredwidth = inchestopoints(6)       if .style <> "table grid"         .style = "table grid"       end if       .applystyleheadingrows = true       .applystylelastrow = true       .applystylefirstcolumn = true       .applystylelastcolumn = true     end     call fillcells(intfields)     selection.endkey unit:=wdstory     selection.typeparagraph     rstemps.movenext   next inti   rstemps.close   connemp.close   set rstemps = nothing   set connemp = nothing   activewindow.activepane.view.showall = true end sub private sub fillcells(intfields integer)   dim intf integer   intf = 0 intfields - 1     dim strfieldname string     strfieldname = right(rstemps.fields(intf).name, _     len(rstemps.fields(intf).name))     selection.typetext text:=strfieldname     selection.paragraphformat.alignment = wdalignparagraphright     selection.moveright unit:=wdcell     selection.fields.add range:=selection.range, _     type:=wdfieldformtextinput     selection.previousfield.select     selection.formfields(1)       .name = "txt" & strfieldname       .enabled = true       .ownhelp = false       .ownstatus = false       .textinput         .edittype type:=wdregulartext, _         default:=rstemps.fields(intf).value, format:=""         .width = 0       end     end     selection.moveleft unit:=wdcell     if intf <> (intfields - 1)       selection.movedown unit:=wdline, count:=1     end if   next intf end sub 

basutilities

option explicit public sub connect(strvar string) dim stremps string, strpath string   stremps = "select tblemployees.[firstname], tblemployees.[lastname], tblemployees.[notes], tblemployees.[photo] "   stremps = stremps & "from tblemployees "   stremps = stremps & "where tblemployees.[country]= '" & strvar & "' order tblemployees.[lastname]"   strpath = thisdocument.path & cstrpath   set connemp = new adodb.connection   set rstemps = new adodb.recordset   connemp.open "provider=microsoft.ace.oledb.12.0;data source='" & strpath & "'"   rstemps.open stremps, connemp, adopenkeyset, adlockoptimistic   call createtables end sub 


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -