|
-
May 25th, 2012, 03:45 AM
#1
Thread Starter
Junior Member
Input box on query
Hi
I'm trying to get a query to handle a input box like so:
Code:
'input box for w/c
inputdate = InputBox(Prompt:="Enter Mondays date", Title:="date Input")
'SET DB AND FIELDS
Set db = CurrentDb
'Set rs = db.OpenRecordset("SELECT * FROM tbl_Schedule WHERE (((tbl_Schedule.Date)='& inputdate &'))")
I notice that the query works in this format:
Code:
Set rs = db.OpenRecordset("SELECT * FROM chaseupEmail WHERE (((chaseupEmail.Date)=#14-may-12#))")
But when I enter the date 14-may-12 in the input box, the query does not recognise the date.
Any help would be greatly appreciated
Matt
Twitter @dancematt
Programmers unite
-
May 25th, 2012, 05:13 AM
#2
Re: Input box on query
But when I enter the date 14-may-12 in the input box, the query does not recognise the date.
you would need to validate the date and make sure it is the correct format for the database
access must be mm/dd/yyyy, regardless of your locale
also as you can see dates should be enclose in # rather than '
so your query should look like
vb Code:
rs = db.OpenRecordset("SELECT * FROM tbl_Schedule WHERE (((tbl_Schedule.Date)=#" & inputdate & "#))")
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 25th, 2012, 05:42 AM
#3
Re: Input box on query
It WOULD recognize it if you put # delimiters around it.... right now your query looks like this:
WHERE (((tbl_Schedule.Date)='& inputdate &'))")
Actually there's two things wrong... first no date delimiters (#) and secondly since you used single tick marks, you inserted the string literal & inputdate & into your query... it should look like this:
WHERE (((tbl_Schedule.Date)=#" & inputdate & "#))")
-tg
-
May 25th, 2012, 09:43 AM
#4
Thread Starter
Junior Member
Re: Input box on query
you my friend, are a hero
thank you very much
Twitter @dancematt
Programmers unite
-
May 25th, 2012, 10:26 AM
#5
Re: Input box on query
if your issue has been resolved, please mark the thread resolved. You can do this by using the Mark as Resolved menu item under the Thread Tools at the top of post 1.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|