Skrmetti
Aug 18th, 1999, 05:29 PM
I have a weird problem, and for once it's not anything related to me personally. Instead, it has to do with a TDBGrid that refuses to display all of the data I put into it. I have used DDL to create a temporary table, filling it with all the data from five other tables, and I want it to display all the information in the grid. As it happens now, all of the column headers appear, but the only columns with data are those representing the first two tables that were added into the Big Table. I tried breakingu up the insertion code, reasoning that maybe the SQL string was just too long for my computer to handle, but unfortunately that did not work. Any suggestions? I'm going to put the code at the bottom here, because it's very long and then a bit longer.
Thanks,
Jonathan
Private Sub cmdExecuteQuery_Click()
MousePointer = 11
'The way to solve the problem of displaying multiple tables is through SQL's DDL (Data
'Definition Language), which allows you to use SQL statements to create tables, fill them
'up with data, delete them, etc., during runtime. This is kind of tricky, but it seems to
'be the only viable option for making the grid display whatever the user wants out of all
'the tables of the SafeShutdown database.
'Create the BigTable with all the fields of the hierarchical tables (i.e., tables FireArea,
'FireZone, Component, Device, Cable - Raceawys can be Inner Joined after BigTable is created)
On Error GoTo ErrBigTable 'If BigTable already exists this will drop the existing one to make way for the new.
CreateTable:
strSQL = "CREATE TABLE tblBigTable ([FireArea] TEXT, [FireZone] TEXT, [Division] TEXT,"
strSQL = strSQL & "[SafeShutdownComments] MEMO, [ComponentNumber] TEXT, [SystemNumber] TEXT)"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN PIDNumber TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN PIDLocation TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN DeviceNumber TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN Location TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN CableNumber TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN DestinationFrom TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN DestinationTo TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN ElectricalDrawings TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
'Fill the fields of BigTable with the values of the hierarchical tables
strSQL = "INSERT INTO tblBigTable SELECT FireArea FROM FireArea"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "INSERT INTO tblBigTable SELECT FireZone,FireArea,Division,SafeShutdownComments FROM FireZone"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "INSERT INTO tblBigTable SELECT ComponentNumber, SystemNumber, PIDNumber, PIDLocation FROM Component"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "INSERT INTO tblBigTable SELECT DeviceNumber, Location FROM Device"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "INSERT INTO tblBigTable SELECT CableNumber, DestinationFrom, DestinationTo, ElectricalDrawings FROM Cable"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
'This is where the search string will be assembled once the BigTable is filled with
'everything:
strSQL = "SELECT * FROM tblBigTable"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
GoTo SubEnd
ErrBigTable:
strSQL = "DROP TABLE tblBigTable"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
GoTo CreateTable
SubEnd:
End Sub
Public Sub Query(strDBPath As String, strSQL As String)
Dim rsRecordset As ADODB.Recordset
Dim strConnect As ADODB.Connection
Dim fld As ADODB.Field
Set strConnect = New ADODB.Connection
With strConnect
.Provider = "MSDataShape.1;Data Provider=Microsoft.Jet.OLEDB.3.51"
.Open strDBPath
End With
Set rsRecordset = New ADODB.Recordset
With rsRecordset
.Open strSQL, strConnect, adOpenStatic, adLockReadOnly
End With
Set TDBGrid1.DataSource = rsRecordset
'Set MSHFlexGrid1.Recordset = rsRecordset
'columnwidth <= This is not currently functional; see "Private Sub Columnwidth()"
'MSHFlexGrid1.Col = 1
'MSHFlexGrid1.Sort = flexSortNumericAscending
'MSHFlexGrid1.Col = 0
'MSHFlexGrid1.Sort = flexSortNumericAscending
'Dim x As Integer
'For x = 0 To 1
'MSHFlexGrid1.MergeCol(x) = True
'Next x
'The MousePointer is currently changing back too quickly. I'd like it
'to stay an hourglass until the grid is finished, but it doesn't want
'to do that. Hmmmm.
MousePointer = 0
End Sub
Thanks,
Jonathan
Private Sub cmdExecuteQuery_Click()
MousePointer = 11
'The way to solve the problem of displaying multiple tables is through SQL's DDL (Data
'Definition Language), which allows you to use SQL statements to create tables, fill them
'up with data, delete them, etc., during runtime. This is kind of tricky, but it seems to
'be the only viable option for making the grid display whatever the user wants out of all
'the tables of the SafeShutdown database.
'Create the BigTable with all the fields of the hierarchical tables (i.e., tables FireArea,
'FireZone, Component, Device, Cable - Raceawys can be Inner Joined after BigTable is created)
On Error GoTo ErrBigTable 'If BigTable already exists this will drop the existing one to make way for the new.
CreateTable:
strSQL = "CREATE TABLE tblBigTable ([FireArea] TEXT, [FireZone] TEXT, [Division] TEXT,"
strSQL = strSQL & "[SafeShutdownComments] MEMO, [ComponentNumber] TEXT, [SystemNumber] TEXT)"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN PIDNumber TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN PIDLocation TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN DeviceNumber TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN Location TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN CableNumber TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN DestinationFrom TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN DestinationTo TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "ALTER TABLE tblBigTable ADD COLUMN ElectricalDrawings TEXT"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
'Fill the fields of BigTable with the values of the hierarchical tables
strSQL = "INSERT INTO tblBigTable SELECT FireArea FROM FireArea"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "INSERT INTO tblBigTable SELECT FireZone,FireArea,Division,SafeShutdownComments FROM FireZone"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "INSERT INTO tblBigTable SELECT ComponentNumber, SystemNumber, PIDNumber, PIDLocation FROM Component"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "INSERT INTO tblBigTable SELECT DeviceNumber, Location FROM Device"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
strSQL = "INSERT INTO tblBigTable SELECT CableNumber, DestinationFrom, DestinationTo, ElectricalDrawings FROM Cable"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
'This is where the search string will be assembled once the BigTable is filled with
'everything:
strSQL = "SELECT * FROM tblBigTable"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
GoTo SubEnd
ErrBigTable:
strSQL = "DROP TABLE tblBigTable"
Query "L:\GSysMod\Clients\Entergy\SafeShutdown\SafeShutdown.mdb", " " & strSQL & " "
GoTo CreateTable
SubEnd:
End Sub
Public Sub Query(strDBPath As String, strSQL As String)
Dim rsRecordset As ADODB.Recordset
Dim strConnect As ADODB.Connection
Dim fld As ADODB.Field
Set strConnect = New ADODB.Connection
With strConnect
.Provider = "MSDataShape.1;Data Provider=Microsoft.Jet.OLEDB.3.51"
.Open strDBPath
End With
Set rsRecordset = New ADODB.Recordset
With rsRecordset
.Open strSQL, strConnect, adOpenStatic, adLockReadOnly
End With
Set TDBGrid1.DataSource = rsRecordset
'Set MSHFlexGrid1.Recordset = rsRecordset
'columnwidth <= This is not currently functional; see "Private Sub Columnwidth()"
'MSHFlexGrid1.Col = 1
'MSHFlexGrid1.Sort = flexSortNumericAscending
'MSHFlexGrid1.Col = 0
'MSHFlexGrid1.Sort = flexSortNumericAscending
'Dim x As Integer
'For x = 0 To 1
'MSHFlexGrid1.MergeCol(x) = True
'Next x
'The MousePointer is currently changing back too quickly. I'd like it
'to stay an hourglass until the grid is finished, but it doesn't want
'to do that. Hmmmm.
MousePointer = 0
End Sub