What I want:
I am working with an MS Access database to produce a report for the Ontario Professional Engineering University Accreditation board. The PEO have their templates in MS Excel and I MUST use their exact format.
I want to output the data from the Access DB to the Excel sheet (easy enough), but I want to copy their formatting when producing a new file. (I do NOT want to keep an empty template file and copy it each time).
So essentially I'm looking to somehow store the template in code. (Other suggestions are welcome!)
What I've tried:
Some of you will read this and think i'm an idiot. But what i tried was to get the data from excel on the MS Clipboard through the API Code and store the DataObject as (i was hoping) some sort of string.
But i could not preserve the formatting or cell shading from the original MS Excel template.
Any suggestions?...
You could store the Excel template(s) within the database by creating a table that includes an Attachment field
creating a record and saving the Excel template as an attachment to that record
and then using VBA code like this to save a new copy of the Excel document to disk whenever you need one:
Option Compare Database
Option Explicit
Public Sub SaveReportTemplateToFile()
Dim cdb As DAO.Database, rowRst As DAO.Recordset, attachRst As DAO.Recordset2, attachField As DAO.Field2
Set cdb = CurrentDb
Set rowRst = cdb.OpenRecordset("SELECT TemplateFile FROM ReportTemplates WHERE ID=1")
Set attachRst = rowRst.Fields("TemplateFile").Value
Set attachField = attachRst.Fields("FileData")
attachField.SaveToFile "C:\Users\Gord\Desktop\" & attachRst.Fields("FileName").Value
Set attachField = Nothing
attachRst.Close
Set attachRst = Nothing
rowRst.Close
Set rowRst = Nothing
Set cdb = Nothing
End Sub
What you are going to have to do is first export all the data into a new sheet of an empty template, then link all the data to the correct place on the template and then remove the sheet with all the data, keeping the data on the template.
As far as I know there is no quicker way to do this, but here is an example: http://www.rogersaccesslibrary.com/forum/topic350.html
It will be quite a job, but doable, if the template is well setup.
Related
In the following microsoft documentation: -
https://learn.microsoft.com/en-us/sql/ado/guide/appendixes/microsoft-data-shaping-service-for-ole-db-ado-service-provider?view=sql-server-2017
this feature is being removed and the suggestion is to use XML. Has anyone done this? I'm wondering what they mean, in terms of loading the structure of what MSDataShape is by using XML, or just to use XML objects?
TIA
I believe this is referring to the FOR XML clause of T-SQL, which performs much the same job as MSDataShape in that it returns hierarchically nested data.
Port your MSDataShape queries to FOR XML queries and change the client to parse the results instead of using the MSDataShape OLEDB provider.
At the client side, SAX or pull parsing would be the best fit to port code that previously used MSDataShape (which also had a move-through-the-records cursor based model).
This is my bit of code that is helpful. My MSDataShape code still works, therefore I propose using that to generate your XML as a template, then use that going forward to load them: -
Dim objShapeMaker As clsShapeMaker
Dim rsoTemp As ADODB.Recordset
Dim strXMLTemplate As String
' Template file
strXMLTemplate = "C:\Temp\Template_GI.xml"
' Create the MSDataShape and save it to XML
Set rsoTemp = objShapeMaker.CreateGI()
rsoTemp.Save strXMLTemplate, adPersistXML
' Now we have the XML in a file going forward, load it in my recordset
Set rsoTemp = New ADODB.Recordset
rsoTemp.Open strXMLTemplate, , , , adCmdFile
' Cleanup
Set rsoTemp = Nothing
Set objShapeMaker = Nothing
If you don't like the idea of generating XML template files to maintain, you could do this via .NET and expose it to COM to use in your VB6/VBA application as mentioned here.
I have made a .NET application that can generate these XML files from simple code lines should anyone want going forward that is similar to the blog listed, however it handles child recordsets with relationships.
EDIT 1: This works great if you have schema set ups without returning data. As far as I can tell, to populate these effectively, it's better to write code to load the structure first, and populate it after from seperate recordsets (which is slower!)
EDIT 2: This is the approach we are taking with a replacement in a .NET Interop. Initially looking at bringing XML from SQL and parsing that back as required. This could be bought back into a DataSet and that's parsed into the target recordset as well, but then the relationship between the tables in the result dataset needs to be set in code rather than the one place in T-SQL with XML output.
Is there a way to determine that UI view show search results?
better to use LotusScript...
I just need to prevent users from doing specific actions to the documents selected in search results view.
Thanks
A view can not be programmatically set to only show search results. This task is usually achieved by using a "SPOFU"- Folder (Shared, Private on First use) and put the search results in there with your Code. There are a lot of things to consider when doing such code, therefor I only add a script snippet on how it would look:
Dim ses as New NotesSession
Dim db as NotesDatabase
Dim dc as NotesDocumentCollection
Set dc = db.FtSearch(...
Call dc.PutAllInfolder( "SearchResults" )
This code is not tested, and it does not provide a way to empty the folder before the search and to open the folder after successfull search, but it should give an idea...
I have to generate report using Data report in vb6. I can able to set Data Source from table but the problem is i have a field that the value is decoded or encrypted i want to encode it so the value become readable.
Ill try to get the value of the rpttextbox that connected to my DB and i hide this textbox and i set rptlabel that will be hold the encode value of rpttextbox.
In sort rptlabel = encode(rpttextbox)
this is my code
Sections("Section1").Controls("lblencode").Caption = encode(Sections("Section1").Controls("rpttextbox_st").???)
how do i get the value of the rpttextbox? TY guys.
If you need to do any processing, reformatting, etc. between the data and the DataReport you can write a data source Class or UserControl to be the middleman (DataSourceBehavior property = vbDataSource).
See Creating a Data Source, Creating Data Sources, and related topics in the VB6 documentation.
I am using two different datasets to populate datagridview my project using visual studio using vb.net. It is windows forms application which is used to display information from the database based on user inputs. Once the information is displayed the user can save the information into a table specifically created to store the report information in order for it to be recalled at a later date. I am now trying to recall this information so have created my dataset in the same way as before and am now trying to invoke a new occurrence of it and this is where the probelm begins. The code is below.
Dim dv2 As New System.Data.DataView
dv2 = New System.Data.DataView(DataSet2.Tables(0), "Status <> ''", "",
DataViewRowState.CurrentRows)
DataTable2TableAdapter.fill(DataSet2.DataTable2, f5.ComboBox2.SelectedValue)
I am getting two issues.
For DataSet2.Tables(0): Reference to a non-shared member requires an object reference
For DataTable2TableAdapter: ’DataTable2TableAdapter’ is not declared. It may be inaccessible due to its protection level.
I dont know why this is happening as I have written the same code here as for my previous data set other than changing the SQL statement behind the dataset at set up. Any thoughts would be welcome as I am totally out of ideas. All questions are welcomed.
Thanks
Try the following code to fix your error number 1....
Dim tablezero as System.Data.DataTable
'
tablezero = DataSet2.Tables(0)
The reason your getting the error is because you are trying to access an object (Table(0)) and it is not visible to the code that is trying to access it, if it was SHARED then it would be visible.
So you can resolve it by defining and object instance/reference to it and then accessing that reference, which in this case i have called "tablezero" (or by making table(0) SHARED - usually not the best bet unlessits neccesary - no point in having something accessible to the whole class it is declared in unless absolutelty neccessary)
It is quite possible the second error may dissapear after just fixing above, then again its difficult to tell without your code for Dataset2
Hope it helps.
I'm trying to figure out how to add a local group to an (On-Demand) Publishing Point, with vbscript.
The group just needs read access to it. The group has (of course) been created first.
System: Windows Server 2008 R2 x64 with Media Services 2008 (for R2). It's not a Domain Controller, there's no Active Directory.
Context: Running a media server with one Pub. Point per movie, and use the group to allow/deny access to that Pub. Point / movie on a per-user basis.
I can add the group manually, but I would really like to do it with a (vb)script.
To do it manually:
(first create a local group).
In Server Manager, click the on-demand Publishing Point, Properties tab, Authorization, WMS Publishing Points ACL Authorization (which of course has to be enabled), right-click it - choose Properties.
Strangely, Groups are by default not enabled in Object Types, so one has to specifically enable them to be able to add the group.
The closest example I've been able to find is this: (it's in VB.Net)
http://msdn.microsoft.com/en-us/library/dd875036%28v=VS.85%29.aspx
My (almost-working) script so far:
Dim Server
Dim ODPubPoint
Dim Plugin
Dim ACLCheckAdmin
Dim AccessCtrlList
Dim objACE
' Create a new WMSServer object.
Set Server = CreateObject("WMSServer.server","localhost")
' Create a new ODPubPoint object.
Set ODPubPoint = Server.PublishingPoints.Item("supersizeme")
' Retrieve the plug-in to be configured.
Set Plugin = ODPubPoint.EventHandlers.Item("WMS Publishing Points ACL Authorization")
' Retrieve the custom interface of the plug-in.
Set ACLCheckAdmin = Plugin.CustomInterface
' Retrieve the list of access control entries.
Set AccessCtrlList = ACLCheckAdmin.AccessControlList
' Create an object to be able to add to the access control list.
Set objACE = CreateObject("AccessControlEntry")
objACE = AccessCtrlList.Add("MEDIESERVER\hest", 16 )
The group does get added, but the script dies with an error:
ppaddgroup.vbs(27, 2) Microsoft VBScript runtime error: Object doesn't support this property or method.
In the VB.Net example it says WMS_ACCESS_CONTROL.WMS_ACL_ALLOW_ALL which I have no idea how to convert from VB.Net to VBScript. I thought it was just a constant, but apparently not.
(and I just want to allow read access, as in WMS_ACL_ALLOW_READ ).
I found the constants on this page:
http://include.wutils.com/com-dll/constants/constants-WMSServerLib.htm
Can anyone come up with the correct way to add a group to a publishing point?
Per greylion's previous edit:
The last line needs to be:
Set objACE = AccessCtrlList.Add("MEDIESERVER\test", 16 )
For some reason, I was convinced that the final act of adding the
group was not supposed to have a "Set" in front. I thought it was only
for creating or defining objects, but apparently it's also for filling
them with actual data. Annoyingly, it almost worked with "Set"
missing, which led me to think I just had some minor detail wrong, but
no way to know what it was.
Mental note: Filling an object with data is NOT like setting a
variable or constant.