Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21278

Tables won't populate.

$
0
0
Just when I thought it was safe to go back into the water, Jaws torn me a new one. My problem now it seems is my data doesn't show up in my database tables. To explain my problem in few word as posssible. I change the coding that I was using to create tables from dao to ado because dao was conflicting the rest of my code, ie, references for dao interferred with the ado coding I had been using and vice versa. But now, even though I can create the tables I need I can't get the data into
the appropiate fields. The program run fine with no error messages, but when open the database and check the tables the field cells are empty. But here's the kicker, the tables I created using dao accepts data with no problem. Playing around with the table settings in the database help pin my problem down to how ado set certain properties, e,g, required, indexies, and the other settings. So here is both my code creating tables. DAO is the first one ADO will be second.


DAO code:

Dim dbsEmployees As Database
Dim rstmytable As TableDef
Dim prpLoop As Property
Dim Name
Dim Password
Dim User
Dim AddName


If TxtConfirm <> TxtPassword Then
MsgBox "Passwords do not match, please try again"
Exit Sub
Else
Set dbsEmployees = OpenDatabase("C:\Employees.mdb")

' Create a new TableDef object.
Set rstmytable = dbsEmployees.CreateTableDef(TxtName.Text)

End If

With rstmytable

' Create fields and append them to the new TableDef
' object. This must be done before appending the
' TableDef object to the TableDefs collection of the
' Employees database.
.Fields.Append .CreateField("Date_ID", dbDate)
.Fields.Append .CreateField("Time_in", dbDate): Format #12:00:00 AM#
.Fields.Append .CreateField("Time_out", dbDate): Format #12:00:00 AM#
.Fields.Append .CreateField("Total_hours", dbText)
.Fields.Append .CreateField("Time_start", dbText)
.Fields.Append .CreateField("Time_Stop", dbText)

' Enumerate Properties collection of new TableDef
' object.
For Each prpLoop In .Properties
On Error Resume Next
If prpLoop <> "" Then Debug.Print " " & _
prpLoop.Name & " = " & prpLoop
On Error GoTo 0
Next prpLoop

' Append the new TableDef object to the Employees
' database.
dbsEmployees.TableDefs.Append rstmytable

Debug.Print "Properties of new TableDef object " & _
"after appending to collection:"

' Enumerate Properties collection of new TableDef
' object.
For Each prpLoop In .Properties
On Error Resume Next
If prpLoop <> "" Then Debug.Print " " & _
prpLoop.Name & " = " & prpLoop
On Error GoTo 0
Next prpLoop
TxtName.SetFocus
Close

End With




ADO code:

Dim catDatabase As ADOX.Catalog
Dim oTable As ADOX.Table
Dim bCreateTable As Boolean
' -------------------------------
On Error GoTo PROC_ERR

'
' Pre conditions. Assume we do not create a table.
'
bCreateTable = False

Set catDatabase = New ADOX.Catalog
With catDatabase
.ActiveConnection = "Provider='Microsoft.Jet.OLEDB.4.0';" & _
"Data Source='C:employee.mdb';"

Set oTable = .Tables(Tex1.text)
End With

PROC_EXIT:
'
' Clean up or do exit conditions and die gracefully.
'
If (bCreateTable) Then
Set oTable = New ADOX.Table
With oTable
.Name = (TxtName.Text)
Call .Columns.Append("Date_ID", adVariant)
Call .Columns.Append("Time_In", adVariant)
Call .Columns.Append("Time_Out", adVariant)
Call .Columns.Append("Total_Hours", adVariant)
Call .Columns.Append("Time_Start", adInteger)
Call .Columns.Append("Time_Stop", adInteger)
End With

Call catDatabase.Tables.Append(oTable)
End If

If (Not catDatabase Is Nothing) Then
Set catDatabase = Nothing
End If
'
' Let the caller know if we created a table.
'
CreateTable = bCreateTable
PROC_ERR:
Select Case Err.Number
Case 3265
'
' The table does not exist, enable the creation flag and
' head for the exit.
'
bCreateTable = True
Err.Clear
Resume PROC_EXIT
Case Is <> 0
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdCreateTable_Click of Form frmMain"
bCreateTable = False
Err.Clear
Resume PROC_EXIT
End Select
End Function

Private Sub cmdCreateTable_Click()
Dim bTableCreated As Boolean

bTableCreated = CreateTable
If (bTableCreated) Then
Call InsertInitialData
End If


Any thoughts and help will be greatly appreciated.

Viewing all articles
Browse latest Browse all 21278

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>