Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 15th, 2006, 02:31 PM
Authorized User
 
Join Date: Feb 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default YYYY and MM in access' SQL select statement

I'm new to this forum. I have tried looking for a solution in the net but have not been able to find one. I have the following SQL string in access(SQL View option):

select * from TableName(M200601) where ....

The portion I'm interested in editing is the date: "M200601". This is hard coded right now into the query. I would like for the year and month to be recognized automatically preceded by an M and passes into the Select string. Is there a way to do this?

Thank you for any input provided!

 
Old February 15th, 2006, 02:47 PM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Create a control in which the user selects the month and year they want to view and plugs it into a field, say fldMonth, fldYear; or a fldDate if you keep them combined.

table_name = "M" & fldYear & fldMonth
or
table_name = "M" & right(fldDate,4) & left(fldDate,2)

Create your query in VBA as:
"SELECT * " & _
"FROM " & table_name & " " & _
"WHERE ..."

Should work I think.

Edit: Can also use listboxes to select the Month/Year.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert dd/MM/yyyy to MM/dd/yyyy Rg2005 VB.NET 2002/2003 Basics 2 November 7th, 2008 06:42 PM
Select date from cell with m/d/yyyy h:mm format mona_upm84 Excel VBA 2 August 10th, 2008 05:58 PM
mm/dd/yyyy to dd/mm/yyyy Ashleek007 Beginning PHP 2 September 27th, 2006 06:35 AM
convert "MM/dd/yyyy" to "dd/MM/yyyy" xin56 General .NET 4 March 28th, 2005 05:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.