Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want this code to work, I have tried all possible combinations and finally posting here. All this code is supposed to do is to get a row from the table using 3 input parameters. The problem comes when using the date in Sql statement, it dosent work but if I use a variable "nam" and change the condition criteria accordingly it works.

Your help will be greatly appreciated.

VB
Dim dbs1 As DAO.Database
Dim rst1 As DAO.Recordset
Dim strSQL1 As String
Dim temp As Date
nam = "DeEx"
 temp = [Forms]![AllProjects1]![Combo3].Value
 temp = Format(temp, "dd-mm-yyyy")
Set dbs1 = CurrentDb
'strSQL1 = "SELECT * FROM AllProjects WHERE Team= '" & nam & "'" & " AND Team= '" & nam & "'"
strSQL1 = "SELECT * FROM AllProjects " & "WHERE [StartDate]=" & Format(temp, "dd.mm.yyyy")
Set rst1 = dbs1.OpenRecordset(strSQL1)
Posted
Updated 28-Aug-12 3:39am
v4
Comments
[no name] 28-Aug-12 9:43am    
Does it work if you format your data to be in the form dd/MM/yyyy?
Maciej Los 28-Aug-12 11:48am    
It should works for dd/mm/yyyy, but default, prefered MS format for date is: MM/dd/yyyy.
[no name] 28-Aug-12 11:50am    
And he is formatting his string to something very weird. Which may or may not be the format of his database.
Maciej Los 28-Aug-12 12:07pm    
Yes, and this is the reason of his trouble. ;)
Maciej Los 28-Aug-12 11:45am    
Please, answer me few simple questions:
1) Why do you use DAO? Access 2k7 default engine: ADO!
2) Is the above code calling from standard module, class module or from UserForm module?
3) Why do you format data as dd.mm.yyy? Is this default format for "AllProjects" table?

1 solution

First of all, read this article[^] and thread on ozgrid forum[^] and all related articles.

To get data from table, use the following query:
SQL
SELECT *
FROM AllProjects
WHERE [StartDate]= #09/18/2012#


I recommend you to build a query and check its content in the run-time using MsgBox, for example:
VB
strSQL1 = "SELECT * FROM AllProjects " & "WHERE [StartDate]=#" & Format(temp, "dd.mm.yyyy") & "#"
MsgBox strSQL1

What you see now?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900