473,385 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Date syntax error in query expression

31
Can someone tell me what I am doing wrong here please?

I have a form with two unbound text boxes formatted to short date and an OK button.

My button code is as follows:

Private Sub cmdOK_Click()

Dim strFilter As String

strFilter = "Between #" & Me.txtStartDate.Value & "# And #" & Me.txtEndDate.Value & "#"

'Open Report before applying the filter
DoCmd.OpenReport "rptDisbursementSummaryReport", acViewPreview

With Reports![rptDisbursementSummaryReport]
.Filter = strFilter
.FilterOn = True
End With
End Sub

I am getting the following error message:

Syntax error (missing operator) in query expression '(Between #12/12/2007# And #11/12/2008#)'.

Many thanks
Dec 11 '08 #1
5 12269
nico5038
3,080 Expert 2GB
The filtering of the report can be passed by using the WHERE parameter of the DoCmd.OpenReport like:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOK_Click()
  2.  
  3. Dim strFilter As String
  4.  
  5. strFilter = "Between #" & Me.txtStartDate.Value & "# And #" & Me.txtEndDate.Value & "#"
  6.  
  7. 'Open Report before applying the filter
  8. DoCmd.OpenReport "rptDisbursementSummaryReport", acViewPreview,,strFilter 
  9.  
  10. End Sub
  11.  
Nic;o)
Dec 11 '08 #2
OzNet
31
Thanks for the advice Nic;o)

However, I am still getting the Syntax error.

I suspect it is something to do with this but I am not sure what is wrong.

strFilter = "Between #" & Me.txtStartDate.Value & "# And #" & Me.txtEndDate.Value & "#"

Thanks
Dec 11 '08 #3
nico5038
3,080 Expert 2GB
Dates are sometimes mis-interpreted due to the local settings, I always use a format statement:
Expand|Select|Wrap|Line Numbers
  1. "Between #" & Format(Me.txtStartDate,"mm-dd-yyyy") & "# And #" & Format(Me.txtEndDate,"mm-dd-yyyy") & "#"
  2.  
Oops, also specify which field to test so the statement should look like:

"TableDateField between xxx and yyy"

Just give it a try.

Nic;o)
Dec 11 '08 #4
OzNet
31
Thanks Nic'o

I tried:
strFilter = "DisbursDate Between #" & Format(Me.txtStartDate.Value, mm - dd - yyyy) & "# And #" & Format(Me.txtEndDate.Value, mm - dd - yyyy) & "#" but I still got the error.

I tried a different approach which is now working:
the OK button code is:
Private Sub cmdOK_Click()

DoCmd.OpenReport "rptDisbursementSummaryReport", acViewPreview
DoCmd.Close acForm, Me.Name

End Sub

In the query field DisbursDate I added:
>=[Forms]![frmMdlDisbursementSummaryReport]![txtStartDate] And <=[Forms]![frmMdlDisbursementSummaryReport]![txtEndDate]

It is doing what I want it to do,

Thanks for your suggestions.
Dec 11 '08 #5
nico5038
3,080 Expert 2GB
Your statement holds too many spaces as you have no surrounding quotes in the format statement, it should look like:
Format(Me.txtStartDate,"mm-dd-yyyy")
instead of your:
Format(Me.txtStartDate.Value, mm - dd - yyyy)
(Access now thinks it's a subtraction)

Your solution will work too, but has one small disadvantage. When you rename the form the query will stop working.

Nic;o)
Dec 11 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
2
by: Aloof | last post by:
Using Access 2000 Windows Server 2003 The following code worked fine until we moved hosting companies StartDate = Request.Form("StartDateMonth") & "/" & Request.Form ("StartDateDay") & "/" &...
1
by: Ken | last post by:
I wrote a function to use in queries that takes a date and adds or subtracts a certain length time and then returns the new value. There are times when my function needs to return Null values. ...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
7
by: John Øllgård Jensen | last post by:
Hi Using MS Asccess 2000: In a query I'm trying to create a new field with following expression: FilmDate: Left(,4) The field "FilmNo" is another text field in the query. This is...
9
by: Rizwan Karedoa | last post by:
Hi experts, I am developing an application, I am using vb 2005 and access. I have many date fields, When I am saving through Query for default date I save 1/1/1500 so when i find that date agian I...
3
by: divya | last post by:
Hi, I have a table tblbwday with 2 fields Name and Birthday.I have written this script for displaying evryday names of the people on that day. <% set objConn...
3
by: shawnmiller77 | last post by:
Need Help ASAP! History: Installed new SBS 2003 server on Monday. Migrated IIS, website and current Access database over to new server. I did not develop the website or Access database. Former...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.