That problem will also happen if the table you’re trying to create has the same name as a table you’ve already created. If so, you can just add a number to the end. If that isn’t the problem, try adding Double quotes around it. In VB.NET I use:
Private Function CreateTable(ByVal Universe As Designer.Universe, ByVal TableName As String, ByRef X As Integer, ByRef Y As Integer, ByVal Derived As Boolean, Optional ByVal TableDesc As String = "") As Designer.Table
Dim NewTable As Designer.Table
Try
NewTable = Universe.Tables.Add(TableName.ToUpper))
TableDesc = """" & TableDesc.Trim("""") & """")
NewTable = Universe.Tables.Item(NewTable.Name).CreateAlias(TableDesc))
Catch ex As Exception
Dim Temp As Integer
Temp = 2
While True
Try
NewTable = Universe.Tables.Item(TableName).CreateAlias("""" & TableDesc & "_" & Temp & """"))
Exit While
Catch ex2 As Exception
Temp += 1
End Try
End While
End Try
Return NewTable
End Using
End Function
That would try to create the table and an alias for it, and if unsuccessful, would try to create just an alias with a number after it. Hopefully this helps you a little.
Hi all,
Thanks for your help.
I’m using VB.NET too.
When i try to add a new table in an empty universe
Universe.Tables.Add(table_name)
I actually do have the new table created in the universe but the table is blank: no column in it.
Why do i get an empty table? Is this Tables.add supposed to brings up all the columns with it or am i supposed to add each column?
Is there a way to add a table (by its name) from the database (that would brings up all its columns and everything) ?
Just like when you insert a table in the Designer basically.
If anyone has a code sample to show an exemple, that would help a lot
Dim Cls As Designer.Class
Dim Obj As Designer.Object
Set Cls = Univ.Classes.Add("Classe Name")
'or Set Cls = Univ.Classes.FindClass("Classe Name") if class already exists
Cls.Description = "blabla"
etc ...
Set Obj = Cls.Objects.Add("ObjectName")
Obj.Type = dsNumericVariable
Obj.Description = "desc"
Obj.Select = "TABLE.COL"
Something similar that actually extracts the objects from the table columns:
Dim Cls As Designer.Class
Dim myTableName As String = "ExampleTable"
Univ.Tables.Add(myTableName)
Univ.RefreshStructure()
Set Cls = Univ.Tables.Item(myTableName).Classes.Add("Class Name")
If “myTableName” actually exists in the database, this would add the table, populate the columns, then create a class with all the columns in it as objects.
Thanks for your reply. I already used “Univ.Joins.Add(Join Condition)” text for this is not working for Alias tables And second this statement show correct join Expression but its selected all field for second table.
Please let me if you have solution for this issue.
I don’t know what to say, it works for me … including fields from aliased tables.
Here is something to try. Create the join manually. Copy the join syntax into Notepad or something, and close the universe without saving it. Now use that EXACT same join syntax in your VBA code. It HAS to work.
Take a look at the Designer SDK documentation, because both the .Universes and .Connections collections have a .Add method. The bigger question is why you would want to do this? Creating universes and connections are a one-time activity, so I’m not sure what value automation has … at least from a best practice approach.
Yes you are rite that this is only one time job but I’m creating universe through SDK code on any database. Now only this are left I’m able to Create new universe and also able to save with any name but when I tried to change universe default name then I’m getting error :
The documentation says .Name is a read/write property, but we all know the documentation can be wrong . This property is the filename, so it makes sense that it can’t be changed. A new universe doesn’t really have a name, so use the .SaveAs method to save the file with the name of your choice.