Monday, April 8, 2013

Using date string in SQL statement MS Access Tip

MS Access normally translate our input date from text box to US-format. So to avoid this we have to convert our date string from text box to US-Format before using it in our SQL statement.


Ok here is the code,

....
USdate = Format(InputDate,"mm/dd/yyyy")
Sqlstring = " Select * from [Table1] where [datadate] = #"& USdate &"# "
....

Hope this help.
Thanes

--------- `

MS Access ปกติแล้วจะแปลวันที่ที่เราป้อนเข้าไปทาง Text box ต่างๆเป็น รูปแบบของ US ก่อนเอาไปประมวลผล ดังนั้นถ้าจะเลี่ยงปัญหานี้ ก็แค่แปลง รูปแบบของวันที่ที่ป้อนไปเป็น US format ก่อน เอาไปรวมใน SQL Statement  แค่นั้น

ตัวอย่าง
....
USdate = Format(InputDate,"mm/dd/yyyy")
Sqlstring = " Select * from [Table1] where [datadate] = #"& USdate &"# "
....

หวังว่าจะช่วยได้ครับ
Thanes

No comments: