我只是一个为我的工作开发应用程序的初学者。任何人请帮助我想加载几个选定的列和选择行输出从查询结果到DataGrid视图控件,我没有在此代码中收到任何错误,但同时我没有达到预期的结果。请帮帮我。附件是运行时屏幕,您无法查看结果:
我的代码
Private Sub Command1_Click()
On Error GoTo ErrorMsg
Set ObjConnection = CreateObject("ADODB.Connection")
Set ObjRecordset = CreateObject("ADODB.Recordset")
FromCutoff = CDate(Text1.Text)
ToCutoff = CDate(Text2.Text)
DataGrid1.ClearFields
DataGrid1.Refresh
Colcount = DataGrid1.Columns.Count
ObjConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\04. Files & Documents\GL TMT\TMT_Database.mdb;Persist Security Info=False"
ObjRecordset.Open "Select [Assign_No], [ERP_No], [MEP_Code], [Standard_Activities], [Site_Specific_Activity_Name], [KPI_Type], [Activity_Nature], [Checklist_Activity], [Due_Date], [Due_Time], [Process_Status], [Process_Completion_Date], [Process_Completion_Time], [Review_Status], [Reviewer_Name] FROM [TMT_ACTIVITY_DATABASE] where [Process_Completed_By_ID] ='" & Environ("username") & "' and [MEP_Code] = '" & Combo1.Text & "' and [Process_Status] IN ('Completed','Not Applicable') and [Process_Completion_Date] between #" & FromCutoff & "# and #" & ToCutoff & "#", ObjConnection, adOpenStatic, adLockOptimistic, adCmdText
DataGrid1.ColumnHeaders = True
DataGrid1.RecordSelectors = True
rcount = ObjRecordset.RecordCount
If rcount > 0 And Colcount < 14 Then
For i = 2 To 14
DataGrid1.Columns.Add (i)
Next i
End If
Me.DataGrid1.Columns(0).Caption = "Assign No."
Me.DataGrid1.Columns(1).Caption = "ERP No."
Me.DataGrid1.Columns(2).Caption = "MEP Code"
Me.DataGrid1.Columns(3).Caption = "Standard Activities"
Me.DataGrid1.Columns(4).Caption = "Site Specific Activity"
Me.DataGrid1.Columns(5).Caption = "KPI Type"
Me.DataGrid1.Columns(6).Caption = "Activity Nature"
Me.DataGrid1.Columns(7).Caption = "Checklist Activity"
Me.DataGrid1.Columns(8).Caption = "Due Date"
Me.DataGrid1.Columns(9).Caption = "Due Time"
Me.DataGrid1.Columns(10).Caption = "Process Status"
Me.DataGrid1.Columns(11).Caption = "Completion Date"
Me.DataGrid1.Columns(12).Caption = "Completion Time"
Me.DataGrid1.Columns(13).Caption = "Review Status"
Me.DataGrid1.Columns(14).Caption = "Reviewer Name"
Set Me.DataGrid1.DataSource = ObjRecordset
ObjConnection.Close
Recordset.Close
Set ObjConnection = Nothing
Set Recordset = Nothing
Exit Sub
ErrorMsg:
MsgBox "Input Error", vbCritical
End Sub