We help IT Professionals succeed at work.

Access Query does not show form value (Date)

HKFuey
HKFuey used Ask the Experts™
on
I have a query and want to bring in a date value off a form like this: -

PeriodEndToUse: [Forms]![Form1]![TxtDate]

This seems to work for a normal text box but not dates, does anyone know why?

SQL:

SELECT tbl_MyTable.MyField, [Forms]![Form1]![TxtDate] AS MyDate
FROM tbl_MyTable;
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2013
Commented:
Try this instead:

1.  Add this function to a standard module:
Public Function GetTheDate() 
       GetTheDate = Forms!Form1.txtDate
End Function

Open in new window


2. Change the SQL as follows:
SELECT tbl_MyTable.MyField, GetTheDate() AS MyDate
FROM tbl_MyTable;

Open in new window

Or use Datevalue([Forms]![Form1]![TxtDate])

Author

Commented:
Both work, thanks!