hello, i have this code
Option Explicit
Dim dbFilename As String
Dim nodeid As String
Dim rs As New ADODB.Recordset
Dim cn As ADODB.Connection
Private Sub DTPicker_start_date_change()
If Me.DTPicker_end_date.Value < Me.DTPicker_start_date.Value Then
Me.DTPicker_end_date.Value = Me.DTPicker_start_date.Value + TimeSerial(24, 0, 0)
End If
refreshRs
End Sub
Private Sub DTPicker_end_date_change()
If Me.DTPicker_end_date.Value < Me.DTPicker_start_date.Value Then
Me.DTPicker_start_date.Value = Me.DTPicker_end_date.Value - TimeSerial(24, 0, 0)
End If
refreshRs
End Sub
Private Sub DTPicker_start_hour_change()
refreshRs
End Sub
Private Sub DTPicker_end_hour_change()
refreshRs
End Sub
Private Sub Form_Load()
Me.pump.AddItem "P1--01"
Me.pump.AddItem "P2--02"
Me.pump.AddItem "P3--03"
Me.pump.AddItem "P4--04"
Me.pump.AddItem "P5--05"
Me.DataGrid.Visible = True
End Sub
Public Sub pump_Click()
refreshRs
End Sub
Public Sub refreshRs()
Dim sqlstr As String
Set cn = New ADODB.Connection
dbFilename = "Report_" & Format(Now, "MM_YY") & ".mdb"
cn.ConnectionString = BuildConnectionString(dbFilename)
cn.Open
sqlstr = "SELECT * From Report WHERE(datevalue(RecDate)<= #" & Format(DTPicker_end_date.Value, "mm/dd/yy") & _
"# and timevalue(RecDate)<= #" & Format(Me.DTPicker_end_hour, "hh:mm:ss") & _
"# and (datevalue(RecDate)>= #" & Format$(Me.DTPicker_start_date, "mm/dd/yy") & "# and timevalue(RecDate)>= #" & _
Format(Me.DTPicker_start_hour, "hh:mm:ss") & "# and Report.NodeID = '" & Me.pump.Text & "'));"
Set rs = cn.Execute(sqlstr)
Set DataGrid.DataSource = rs
DataGrid.Refresh
Me.Caption = "number of records: " & rs.RecordCount
cn.Close
Debug.Print sqlstr
End Sub
in the form_load i have one combobox,4datepickers(2 for selecting dates and 2 for selecting hours) and one datagrid where the results of a database(.mdb) must be shown.i want when i click from the combobox a pump or when i change a date/hour from the datepicker the refresh sub to select the exact values from the database.when i run the sqlstr in the immediate window it shows me that works fine but in the datagrid no results are entered.why is that happenning?also the cn connection which refers to the database seems to work fine.any ideas ?please help.thx