|
-
Mar 8th, 2005, 08:45 PM
#1
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:
Dim cn As New ADODB.Connection 'connection
Dim rs As New ADODB.Recordset 'recordset
Dim strTime 'date of entry
Dim strdate
Dim strSQL As String
'initialize variable
strTime = FormatDateTime("10:04:00", vbLongTime)
strdate = FormatDateTime("03/07/05", vbShortDate)
'get date of entry from user
'open connection /database located in same folder as project
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db4.mdb;Persist Security Info=False"
strSQL = "select * FROM AS_Createsched " & _
" WHERE (((AS_Createsched.CSIN_dates) = # " & strdate & " #) " & _
" and (AS_Createsched.CSIN_times = # " & strTime & " #)) "
rs.Open strSQL, cn, adOpenKeyset, adLockOptimistic, adCmdText
Debug.Print rs.Fields(4)
If rs.State = adStateOpen Then rs.Close
Last edited by dglienna; Mar 10th, 2005 at 02:53 PM.
-
Mar 9th, 2005, 04:20 AM
#2
Re: Access Date Time
Code:
" WHERE (((AS_Createsched.CSIN_dates) = # " & strdate & " #) " & _
You have spaces between the hash and the date - remove these and retry
Also try as a full string to make sure it works first then put variables in
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Mar 10th, 2005, 02:53 PM
#3
Re: Access Date Time
The space didn't make a difference. We solved it anyways.
http://www.vbforums.com/showthread.php?t=327693
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|