AnsweredAssumed Answered

select by Date personal geodatabase

Question asked by geonetadmin on Jan 31, 2011
Latest reply on Feb 15, 2011 by geonetadmin
Original User: alnesbit

Hello all,

I'm trying to populate a combo box with the date values currently in my table within a personal geodatabase (not a feature class, just a table). Then the user will select one of those dates and the records with that date will be selected. Pretty simple. I have the combo box getting filled with the correct values. But I can't get the code to work for the selection and it has to do with the date formatting. Can anyone help?

 Private Sub cmdSelectDate_Click()
  
  Dim pMxDoc As IMxDocument
  Dim pMap As IMap
  Dim UserInput1 As String
  Dim i As Integer
  Dim query1 As String
  Dim FeatLayer As IFeatureLayer
  Dim pActiveView As IActiveView
  
  Set pMxDoc = ThisDocument
  Set pActiveView = pMxDoc.ActiveView
  UserInput1 = cboSelectDate.Text
   
  If TypeOf pActiveView Is IPageLayout Then
    Set pMxDoc.ActiveView = pMxDoc.FocusMap
    pMxDoc.ActiveView.Refresh
  End If
  Set pMap = pMxDoc.FocusMap
  
 'Define/get the table
 
  Dim pTabCollection As IStandaloneTableCollection
  Dim pStTable As IStandaloneTable
  Dim pSRTable As ITable
  Set pTabCollection = pMap
  Dim pTableSel As ITableSelection
  Dim pTableSelSet As ISelectionSet
  
  'Get the table
    For i = 0 To pTabCollection.StandaloneTableCount - 1
        If pTabCollection.StandaloneTable(i).Name = "Service_requests" Then
            Set pStTable = pTabCollection.StandaloneTable(i)
            Set pSRTable = pStTable.Table
            'make the query filter
            query1 = "RequestDate = '" & UserInput1 & Format(RequestDate, "MM/DD/YYYY") & "'" 'doesn't work
           'query1 = "RequestDate = #02-05-2011 00:00:00# " , this hardcoded works
           'date in table and the combo box looks like MM/DD/YYYY
            Dim qFil As IQueryFilter
            Set qFil = New QueryFilter
            qFil.WhereClause = query1
         ' MsgBox (query1)
            Set pTableSel = pStTable
            
            '===select the table rows that meets the query and put it in a selection set
            pTableSel.SelectRows qFil, esriSelectionResultNew, False
            
            Set pTableSelSet = pTableSel.SelectionSet
            
            MsgBox pTableSel.SelectionSet.Count
              
              '===refresh the view
            pMxDoc.ActiveView.Refresh
            
        End If
    Next i
    
    frmSelectDate.Hide
End Sub


Thanks in advance,

Attachments

Outcomes