EDN Admin
Well-known member
Hi, I seem to be having a problem populating the datagrid in my project. I get no error message, the program run through with no problem its just that the grid is still empty. I have run the program through step by step and held the the cursor over the values and variables and the data appears to where they are supposed to be. I must missing something, I just dont know what it is. Please look over my code and try to find what it is I am doing wrong.
Private Sub Command1_Click()
Dim Employees As adodb.Connection
Dim rstmytable As adodb.Recordset
Dim Time_out
Dim Time_in
Dim Total_Hours
Dim Date_Id As Date
Text1.SetFocus
DataGrid1.Caption = Text1.Text
Set rstmytable = New adodb.Recordset
Set Employees = New adodb.Connection
Employees.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Employees.mdb"
rstmytable.Open (Text1.Text), Employees, adOpenStatic, adLockOptimistic, adCmdTableDirect
Set DataGrid1.DataSource = rstmytable
With DataGrid1
.Columns(0).DataField = rstmytable.Fields("Date_Id").Value
.Columns(1).DataField = rstmytable.Fields("Time_in").Value
.Columns(2).DataField = rstmytable.Fields("Time_out").Value
.Columns(3).DataField = rstmytable.Fields("Total_Hours").Value
End With
DataGrid1.HoldFields
DataGrid1.Rebind
End Sub
As you can see I am attempting to open a yet determined table by using the text1.text as its name. I have been using this technique throughout my project with no problem, to create tables and enter data into the tables. From what I can tell, the textbox variable is working, the table is being opened and accessed but the grid is not being populating. All help will be greatly appreciated.
P.S.
Upon further examination I have traced my problem to the Datagrid datasource property line, and even though all other references to my variable seem to yield my desired affects, the value for the datagrid datasource remains at "Nothing" , thus explaining why the grid does not populate. So now my problem is assigning the proper datasoure to the grid using the textbox text. Again all help will be greatly appreciated.
View the full article
Private Sub Command1_Click()
Dim Employees As adodb.Connection
Dim rstmytable As adodb.Recordset
Dim Time_out
Dim Time_in
Dim Total_Hours
Dim Date_Id As Date
Text1.SetFocus
DataGrid1.Caption = Text1.Text
Set rstmytable = New adodb.Recordset
Set Employees = New adodb.Connection
Employees.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Employees.mdb"
rstmytable.Open (Text1.Text), Employees, adOpenStatic, adLockOptimistic, adCmdTableDirect
Set DataGrid1.DataSource = rstmytable
With DataGrid1
.Columns(0).DataField = rstmytable.Fields("Date_Id").Value
.Columns(1).DataField = rstmytable.Fields("Time_in").Value
.Columns(2).DataField = rstmytable.Fields("Time_out").Value
.Columns(3).DataField = rstmytable.Fields("Total_Hours").Value
End With
DataGrid1.HoldFields
DataGrid1.Rebind
End Sub
As you can see I am attempting to open a yet determined table by using the text1.text as its name. I have been using this technique throughout my project with no problem, to create tables and enter data into the tables. From what I can tell, the textbox variable is working, the table is being opened and accessed but the grid is not being populating. All help will be greatly appreciated.
P.S.
Upon further examination I have traced my problem to the Datagrid datasource property line, and even though all other references to my variable seem to yield my desired affects, the value for the datagrid datasource remains at "Nothing" , thus explaining why the grid does not populate. So now my problem is assigning the proper datasoure to the grid using the textbox text. Again all help will be greatly appreciated.
View the full article