Solved

Change Recordsource using SQL

Posted on 1998-05-05
1
157 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

15 Experts available now in Live!

Get 1:1 Help Now