How to use a property set in a dialog - installshield

I'm using InstallShield Professional 2016. I have an SQLLogin dialog, which creates a property IS_SQLSERVER_DATABASE for the server name, and I'll need to use this property in an InstallScript script to create the final connection string.
How can I get the value of IS_SQLSERVER_DATABASE in the script to use it?

As you said, SQLLogin dialog will set the IS_SQLSERVER_DATABASE property and if you write with InstallScript, just use this property directly ...
function STRING getConnectionString()
STRING strConnection;
begin
strConnection = IS_SQLSERVER_DATABASE ^ " your connection parameters";
return strConnection;
end;
And if you write with, for example, VBScript ...
szSqlDB = Session.Property("IS_SQLSERVER_DATABASE")

Related

Change built-in Document properties without opening

I am attempting to run the below line of code in a sub. The purpose of the sub overall is to automatically create agendas for recurring meetings, and notify the relevant people.
'Values for example;
MtgDate = CDate("11/06/2020")
Agenda ="Z:\Business Manual\10000 Management\11000 Management\11000 Communications\Operations Meetings\11335 - OPS CCAR Performance Review Agenda 11.06.20.docx" 'NB it's a string
'and the problematic line:
Word.Application.Documents(Agenda).BuiltinDocumentProperties("Publish Date") = MtgDate
Two questions:
1) Can I assign a document property just like that without opening the document? (bear in mind this vba is running from an excel sheet where the data is stored)
2) Will word.application.documents accept the document name as a string, or does it have to be some other sort of object or something? I don't really understand Word VBA.
Attempts so far have only resulted in
runtime error 427 "remote server machine does not exist or is
unavailable"
or something about a bad file name.
Although Publish Date can be found under Insert > Quick Parts > Document Property it isn't actually a document property. It is a "built-in" CustomXML part, a node of CoverPageProperties, and can be addressed in VBA using the CustomXMLParts collection.
The CustomXML part is only added to the document once the mapped content control is inserted.
Below is the code I use.
As already pointed out for document properties the document must be open.
Public Sub WriteCoverPageProp(ByVal strNodeName As String, ByVal strValue As String, _
Optional ByRef docTarget As Document = Nothing)
'* Nodes: Abstract, CompanyAddress, CompanyEmail, CompanyFax, CompanyPhone, PublishDate
'* NOTE: If writing PublishDate set the content control to store just the date (default is date and time).
'* The date is stored in the xml as YYYY-MM-DD so must be written in this format.
'* The content control setting will determine how the date is displayed.
Dim cxpTarget As CustomXMLPart
Dim cxnTarget As CustomXMLNode
Dim strNamespace As String
If docTarget Is Nothing Then Set docTarget = ActiveDocument
strNodeName = "/ns0:CoverPageProperties[1]/ns0:" & strNodeName
strNamespace = "http://schemas.microsoft.com/office/2006/coverPageProps"
Set cxpTarget = docTarget.CustomXMLParts.SelectByNamespace(strNamespace).item(1)
Set cxnTarget = cxpTarget.SelectSingleNode(strNodeName)
cxnTarget.Text = strValue
Set cxnTarget = Nothing
Set cxpTarget = Nothing
End Sub
You cannot modify a document without opening it. In any event, "Publish Date" is not a Built-in Document Property; if it exists, it's a custom one.
Contrary to what you've been told, not all BuiltinDocumentProperties are read-only; some, like wdPropertyAuthor ("Author"), are read-write.
There are three main ways you could modify a Word document or "traditional" property (which are the ones you can access via .BuiltInDocumentProperties and .CustomProperties):
a. via the Object Model (as you are currently trying to do)
b. for a .docx, either unzipping the .docx, modifying the relevant XML part, and re-zipping the .docx.
c. For "traditional" properties, i.e. the things that you can access via .BuiltInDocumentProperties and .CustomDocumentProperties, in theory you can use a Microsoft .dll called dsofile.dll. But it hasn't been supported for a long time, won't work on Mac Word and the Microsoft download won't work on 64-bit Word. You'd also have to distribute and support it.
But in any case, "Publish Date" is not a traditional built-in property. It's probably, but not necessarily, a newer type of property called a "Cover Page Property". Those properties are in fact pretty much as "built-in" as the traditional properties but cannot be accessed via .BuiltInDocumentProperties.
To modify Cover Page properties, you can either use the object model or method (b) to access the Custom XML Part in which their data is stored. Method (c) is no help there.
Not sure where your error 427 is coming from, but I would guess from what you say that you are trying to see if you can modify the property in a single line, using the fullname of the document in an attempt to get Word to open it. No, you can't do that - you have to use GetObject/CreateObject/New to make a reference to an instance of Word (let's call it "wapp"), then (say)
Dim wdoc As Word.Document ' or As Object
Set wdoc = wapp.Documents.Open("the fullname of the document")
Then you can access its properties, e.g. for the read/write Title property you can do
wdoc.BuiltInDocumentProperties("Title") = "your new title"
wdoc.Save
If Publish Date is the Cover Page Property, once you have a reference to the Word Application and have ensured the document is open you can use code along the following lines:
Sub modPublishDate(theDoc As Word.Document, theDate As String)
' You need to format theDate - by default, Word expects an xsd:dateTime,
' e.g. 2020-06-11T00:00:00 if you only care about the date.
Const CPPUri As String = "http://schemas.microsoft.com/office/2006/coverPageProps"
Dim cxn As Office.CustomXMLNode
Dim cxps As Office.CustomXMLParts
Dim nsprefix As String
Set cxps = theDoc.CustomXMLParts.SelectByNamespace(CPPUri)
If cxps.Count > 0 Then
With cxps(1)
nsprefix = .NamespaceManager.LookupPrefix(CPPUri)
Set cxn = .SelectSingleNode(nsprefix & ":CoverPageProperties[1]/" & nsprefix & ":PublishDate[1]") '/PublishDate[1]")
If Not (cxn Is Nothing) Then
cxn.Text = theDate
Set cxn = Nothing
End If
End With
End If
Set cxps = Nothing
As for this, "Will word.application.documents accept the document name as a string", the answer is "yes", but Word has to have opened the document already. as mentioned above. Word can also accept an integer index into the .Documents collection and may accept just the name part of the FullName string.
Finally, if you do end up using a "traditional Custom Document Property", even after you have set the property and saved the document (approximately as above) you may find that the new property value has not actually saved! If so, that's down to an old error in Word where it won't save unless you have actually visited the Custom Document Property Dialog or have modified the document content in some way, e.g. adding a space at the end.

Language Service Submit: Error '91'

I followed the solution posted in below link to execute a simple SAS Query through VBA:
Calling SAS through VBA
Dim obObjectFactory As New SASObjectManager.ObjectFactory
Dim obObjectKeeper As New SASObjectManager.ObjectKeeper
Dim obServer As New SASObjectManager.ServerDef
Dim obSAS As SAS.Workspace
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
obServer.MachineDNSName = "xxxx#company.com"
obServer.Protocol = ProtocolBridge
obServer.Port = 8561
obObjectFactory.LogEnabled = True
Set obSAS = obObjectFactory.CreateObjectByServer("sas", False, obServer, "", "")
obSAS.LanguageService.Submit "PROC SQL; CREATE TABLE ME.TABLE1; RUN;" 'Error at submit
But I'm getting error at the above submit line as "Object variable or With block variable not set"
You are trying to create an Asynchronous connection. I would try to create a syncronous connection instead (change second parameter to true).
Set obSAS = obObjectFactory.CreateObjectByServer("sas", True, obServer, "", "")
Synchronous indicates whether a connection is synchronous or
asynchronous. The synchronous connection is most frequently used and
is the simplest connection to create. If this parameter equals TRUE,
CreateObjectByServer does not return until a connection is made. If
this parameter equals FALSE, the function returns a null value
immediately. When a connection is made, the object is stored in the
ObjectKeeper.
From SAS documentation. Thus why your variable is Nothing right away.
http://support.sas.com/rnd/itech/doc9/dev_guide/dist-obj/winclnt/omcreate.html
Now for the Submit method, I suggest you add some error checking code like
If obSAS Is Nothing Then
MsgBox("Connection failed")
Else
obSAS.LanguageService.Submit "PROC SQL; CREATE TABLE ME.TABLE1; RUN;" 'Error at submit
End If
That above will answer your question of why you are getting the error Object variable or With block variable not set.
For the later Run Time Error '-2147213310 (80042002)' that is a different issue/question. And you should try to contact SAP tech support, with the information you provided there is nothing much we can do. The error must give you additional information in form of html tags. From the link you supplied, it seems this error is caused by a bad connection settings/parameters.
The workspaceservers default port is 8591. Perhaps the
workspaceserver also runs on a different machine. Connect to your
profile, go to the serverlist, locate the server you want to connect
to and right click the context menu "properties" to see the right
connection profile for your workspaceserver.
BTW: if you are using IWA (integrated windows authentication) you must
not provide a username and password (Nothing).
Set obSAS = obObjectFactory.CreateObjectByServer("sas", True, obServer, Nothing, Nothing)

MS Access: Choosing Worksheet from Excel Workbook

I'm writing some code in MS Access and I reached to the point where user needs to choose on which worksheet of an Excel workbook there need to be performed some operation. I don't know, what name of this worksheet is or on which position it is placed.
I was thinking about a solution which will show user a form (as modal form) with listbox containing all sheets names'. When user click one of them form will show aside A1:J10 range (so user can choose the right one worksheet). After confirming choosen worksheet it will return as worksheet object.
Every thing was great untill I wanted to pass a object variable to the form. In openArgs I can only pass a string. I was even thinking about a class which will open this form but it's still no luck with passing object parameter.
I'm trying to avoid global/public variables.
Any ideas?
Assuming your object is wsObj, can't you just use wsObj.Name ?
Also have a look at wsObj.CodeName, which may be interesting as well.
There are many possibilities to send some value between objects.
A) Using Global vars into ACCESS Vba module
Global yourvariable As String
if you need some different value can use Variant, Single, etc.
B) Using Windows Register
To save value:
SaveSetting "yourprojectname", "Settings", "yourvariable", yourvalue
To retrieve value:
retvalue = GetSetting("yourprojectname", "Settings", "yourvariable", "your_default_value_if_not_exist")
C) Using OpenArg into Open Form command procedure
DoCmd.OpenForm "stDocName", acNormal, "filter_if_needed", "stlinkcriteria", acFormEdit, acWindowNormal, "arguments_forOpenArgs"
On destination form
Private Sub Form_Open(cancel as integer)
your_args=Me.OpenArgs
On all three possible solutions you can send more than one value using a chain with vars and values, an example:
myvar_mutiple="name=John Doe|address=Rua del Percebe 34|location=Madrid|phone=34 91 1234567"
On this example i used "pipe" (AltGr on key 1) char to separate each var=value
Then on destination procedure only need split each pair:
splitvar=Split(myvar_multiple,"|")
With this you obtain for each "splitvar" an element like "name=John Doe"
Do again an split with "=" to obtain variable an value. For each value you can reassign the result to a local vars.
Full code example:
if me.OpenArgs<>"" then
splitvar=Split(me.OpenArgs,"|")
for x=0 to ubound(splitvar)
tmpsplit=Split(splitvar(x),"=")
paramvars=tmpsplit(0)
paramvalue=tmpsplit(1)
select case paramvars
case "name"
stname=paramvalue
case "address"
straddress=paramvalue
case "location"
strlocation=paramvalue
case "phone"
strphone=paramvalue
end select
next
end if
Some recommendations that i use for this code "multiple vars":
- always use Low Case variable or change this:
paramvars=tmpsplit(0)
by
paramvars=lcase(tmpsplit(0))
-if you need to use "=" into value you can change by other alternative char or search the first "=" form left (i used this solution instead Split)
paramvars=trim(lcase(left(splitvar(x),len(splitvar(x))-(len(splitvar(x))-instr(splitvar(x),"="))-1)))
remember that you can send any value and can be converted on destination code. On this sample i use only String so you can use cLng or cInt etc.
Over your solution to select Sheet on excel from Access i think there are better alternatives.
IN the forms Module you can declare a property as object and then set that property once loaded. So in the form module
Option Explicit
Private myObj as object
Property Set DesiredWorksheet(o as object)
set myobj = o
End
and then in your code
Load myform
set myform.desiredworksheet = wsObj
myform.show
Ahh, sorry I was writing Excel not Access!!!
Docmd.openform f
f.desiredworksheet = ws.obj
docmd.openform f, windowmode:=acdialog
ought to work

GetOleDbSchemaTable throws exception becaues it doesn't find the object sheet$'Print_Area'

I'm trying to expose the column names from excel in a vb.net application. The code looks like this.
Dim EXCEL_CONNECTION_TEMPLATE As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES;'"
Using con As OleDbConnection = New OleDbConnection(String.Format(EXCEL_CONNECTION_TEMPLATE, savePath))
con.Open()
Dim schema As DataTable = con.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, Nothing)
DoStuffWith(schema)
End Using
After execution i get an exception throwed by GetOleDbSchemaTable:
The Microsoft Jet database engine could not find the object
''sheetname $'Print_Area'. Make sure the object exists and that you
spell its name and the path name correctly.
System.Data.OleDb.OleDbException
It looks like, that GetOleDbSchemaTable has some problem with the sheetnames if they contains space and has print area defined with it on the same time.
Tried to supply parameters like:
Dim schema As DataTable = con.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, New Object() {Nothing, Nothing, "sheetname $"})
This way it didn't throwed the exception but returned with no value.
Any tip / workaround / suggestion is welcomed. And it's obviously not an option to ask the users not to include space and print area in the excel file they uploads.
Found the solution.
It seems that if any of the sheet names in the uploaded excel file contains space, the oledb wraps it between single quote. This seems to working now:
Dim schema As DataTable = con.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, New Object() {Nothing, Nothing, "'sheetname $'"})

Passing file path in Delphi from TOpenDialog as a string

I'm trying to make use of the TOpenDialog in order to pass the path to selected file to the AdoConection and load the content of the Excel file to the table. I'm currently attempting the code below but the last part of the code does not connect to the Excel returning an error:
[dcc32 Error] sample_map.pas(80): E2010 Incompatible types: 'string' and 'TOpenDialog'
procedure TForm1.Button1Click(Sender: TObject);
var
openDialog : TOpenDialog; // Open dialog variable
strConn : WideString; // Declare wide string for the connection
begin
// Create the open dialog object - assign to our open dialog variable
openDialog := TOpenDialog.Create(self);
// Set up the starting directory to be the current one
openDialog.InitialDir := GetCurrentDir;
// Only allow existing files to be selected
openDialog.Options := [ofFileMustExist];
// Allow only .dpr and .pas files to be selected
openDialog.Filter :=
'Excel 2003 and older|*.xls|Excel 2007 and older|*.xlsx';
// Select pascal files as the starting filter type
openDialog.FilterIndex := 2;
// Display the open file dialog
if openDialog.Execute
then ShowMessage('File : '+openDialog.FileName)
else ShowMessage('Open file was cancelled');
// Free up the dialog
openDialog.Free;
// Connect the Excel file
strConn:='Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=' + openDialog + ';' +
'Extended Properties=Excel 8.0;';
AdoConnection1.Connected:=False;
AdoConnection1.ConnectionString:=strConn;
end;
openDialog is an instance of a file dialog. It is not a string. You need to read the FileName property of the file dialog object like this:
openDialog.FileName
In fact you already use that in one of your ShowMessage calls.
Do make sure that you read this property before calling Free, a mistake present in the code in the question.
In fact you do need to get in to the habit of using try/finally to protect resources. Any time you create an instance of a class you need to make sure that it will be destroyed even in the face of an exception. In your code you need to write it like this:
openDialog := TOpenDialog.Create(self);
try
.... // use openDialog to let user choose file:
strConn := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=' + openDialog.FileName + ';' +
'Extended Properties=Excel 8.0;';
finally
openDialog.Free; // executes no matter what, even if exception raised, etc.
end;
I also don't think you need to use WideString here. If you use a Unicode Delphi then you can use the native string type which is an alias for UnicodeString. If your Delphi is pre-Unicode, then you can also safely use string, an alias for AnsiString in that case. The literals you use are ASCII. The file dialog is an ANSI control and so openDialog.FileName is also ANSI. Nothing to be gained using WideString.
Finally, you are mixing up, all in one function, code to select a filename, and code to work on a database connection. It is better to separate concerns. Create a method that simply returns a filename, obtained by letting the user choose through a dialog. And add a method to work on the database connection, that is passed a filename as a parameter.
You need to get the OpenDialog.FileName prior to freeing the dialog:
OpenDialog := TOpenDialog.Create(nil);
try
// Set up the OpenDialog as before
// Display the open file dialog
if openDialog.Execute then
begin
strConn := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=' + openDialog.FileName + ';' +
'Extended Properties=Excel 8.0;';
// Connect the Excel file
AdoConnection1.Connected:=False;
AdoConnection1.ConnectionString:=strConn;
else
ShowMessage('Open file was cancelled');
finally
// Free up the dialog
openDialog.Free;
end;
Of course, you're working much too hard. The Dialogs unit has a much easier way to do this using the PromptForFilename function, which eliminates the need to create and free the dialog entirely:
var
FileName: string;
begin
FileName := '';
if PromptForFileName(FileName, // Chosen filename holder
'Excel 2003 and older|*.xls|Excel 2007 and older|*.xlsx'; // Filter(s) (optional)
'.xlsx', // Default extension (opt)
'Choose file', // Dialog title (opt)
GetCurrentDir, // Initial dir (opt)
False) then // Is it a save dlg? (opt)
begin
strConn := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=' + FileName + ';' +
'Extended Properties=Excel 8.0;';
// Connect the Excel file
AdoConnection1.Connected:=False;
AdoConnection1.ConnectionString:=strConn;
end
else
ShowMessage('Dialog cancelled.');
end;
As a side note, in case you don't know: You can select all Excel files (both .xls and .xlsx) with a single filter if you enter it as .xls*, as in Excel Files|*.xls*.
And, as David says, the best way would be to separate out the code that gets the filename and the code that does the connection as separate functions. Call the first to get the filename, and then pass that filename to the second to actually do the connecting if a filename is selected.

Resources