Solved

Change Recordsource using SQL

Posted on 1998-05-05
1
158 Views
Last Modified: 2006-11-17
I would like to change my recordsource using SQL and filter my recordsouce using Date.. So, I try to create source code like this

data1.recordsource = "select * from mytable where proddate = " & maskedbox1.text

It show nothing , So, I try

data1.recordsource = " select * from mytable where proddate = " & "'" & maskedbox1.text & "'"
It show an error data type mismatch..

So, I try for declare variable as date

dim sdate as date

sdate = proddate

data1.recordsource = "select * from mytable where proddate = " & sdate

It still show nothing, even I try

data1.recordsource = "select * from mytable where proddate = " & "5/5/98"

It still show nothing.. How could I solve this problem?

PS. I use MS-Access 95 as my database and proddate is a field use Date as data type , format shortdate..

Thank you in advance.
0
Comment
Question by:Mcblake
1 Comment
 
LVL 5

Accepted Solution

by:
dirtdart earned 50 total points
ID: 1440265
When comparing literal dates within Access, the date must be surrounded by the pound sign, so that your SQL statement would end up looking like this:

data1.recordsource = "select * from mytable where proddate = #" & maskedbox1.text & "#"

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now