Results 1 to 3 of 3

Thread: Access Date Time [Resolved]

Threaded View

  1. #1

    Thread Starter
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Resolved Access Date Time [Resolved]

    I tried to help someone, and realized that I didn't have a good sample to use of doing a date/time query from VB against an Access table. The only way that I can return any data is by using the LIKE operator, and don't want to do that. The latest thing was declaring variants instead of date, and using formatdatetime to convert the date and time. Still, I get no records returned!

    VB Code:
    1. Dim cn As New ADODB.Connection 'connection
    2.   Dim rs As New ADODB.Recordset 'recordset
    3.   Dim strTime  'date of entry
    4.   Dim strdate
    5.   Dim strSQL As String
    6.   'initialize variable
    7.   strTime = FormatDateTime("10:04:00", vbLongTime)
    8.   strdate = FormatDateTime("03/07/05", vbShortDate)
    9.   'get date of entry from user
    10.  
    11.   'open connection /database located in same folder as project
    12.   cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db4.mdb;Persist Security Info=False"
    13.  
    14.     strSQL = "select  * FROM AS_Createsched " & _
    15.           " WHERE (((AS_Createsched.CSIN_dates) = # " & strdate & " #) " & _
    16.           " and (AS_Createsched.CSIN_times =  # " & strTime & " #)) "
    17.    
    18.     rs.Open strSQL, cn, adOpenKeyset, adLockOptimistic, adCmdText
    19.    
    20.   Debug.Print rs.Fields(4)
    21.  
    22.   If rs.State = adStateOpen Then rs.Close
    Last edited by dglienna; Mar 10th, 2005 at 02:53 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width